本文整理匯總了Python中dash_core_components.Location方法的典型用法代碼示例。如果您正苦於以下問題:Python dash_core_components.Location方法的具體用法?Python dash_core_components.Location怎麽用?Python dash_core_components.Location使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dash_core_components
的用法示例。
在下文中一共展示了dash_core_components.Location方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: display_page
# 需要導入模塊: import dash_core_components [as 別名]
# 或者: from dash_core_components import Location [as 別名]
def display_page(pathname):
print(pathname)
if pathname == '/':
return html.Div([
html.Div('You are on the index page.'),
# the dcc.Link component updates the `Location` pathname
# without refreshing the page
dcc.Link(html.A('Go to page 2 without refreshing!'), href="/page-2", style={'color': 'blue', 'text-decoration': 'none'}),
html.Hr(),
html.A('Go to page 2 but refresh the page', href="/page-2")
])
elif pathname == '/page-2':
return html.Div([
html.H4('Welcome to Page 2'),
dcc.Link(html.A('Go back home'), href="/"),
])
else:
return html.Div('I guess this is like a 404 - no content available')
# app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
示例2: main_layout_sidebar
# 需要導入模塊: import dash_core_components [as 別名]
# 或者: from dash_core_components import Location [as 別名]
def main_layout_sidebar():
"""Dash layout with a sidebar"""
return html.Div(
[
dbc.Container(
fluid=True,
children=dbc.Row(
[
dbc.Col(
make_sidebar(className="px-2"), width=2, className="px-0"
),
dbc.Col(id=server.config["CONTENT_CONTAINER_ID"], width=10),
]
),
),
dcc.Location(id=server.config["LOCATION_COMPONENT_ID"], refresh=False),
]
)
示例3: add_dash
# 需要導入模塊: import dash_core_components [as 別名]
# 或者: from dash_core_components import Location [as 別名]
def add_dash(server):
"""
Adds dash support to main D-Tale Flask process.
:param server: main D-Tale Flask process
:type server: :class:`flask:flask.Flask`
:return: server with dash added
:rtype: :class:`flask:flask.Flask`
"""
dash_app = DtaleDash(
server=server, routes_pathname_prefix="/charts/", eager_loading=True
)
# Since we're adding callbacks to elements that don't exist in the app.layout,
# Dash will raise an exception to warn us that we might be
# doing something wrong.
# In this case, we're adding the elements through a callback, so we can ignore
# the exception.
dash_app.config.suppress_callback_exceptions = True
dash_app.layout = html.Div(
[dcc.Location(id="url", refresh=False), html.Div(id="popup-content")]
)
dash_app.scripts.config.serve_locally = True
dash_app.css.config.serve_locally = True
init_callbacks(dash_app)
return dash_app.server
示例4: main_layout_header
# 需要導入模塊: import dash_core_components [as 別名]
# 或者: from dash_core_components import Location [as 別名]
def main_layout_header():
"""Dash layout with a top-header"""
return html.Div(
[
make_header(),
dbc.Container(
dbc.Row(dbc.Col(id=server.config["CONTENT_CONTAINER_ID"])), fluid=True
),
dcc.Location(id=server.config["LOCATION_COMPONENT_ID"], refresh=False),
]
)
示例5: create_app
# 需要導入模塊: import dash_core_components [as 別名]
# 或者: from dash_core_components import Location [as 別名]
def create_app(dir_name):
def encode(name):
path = os.path.join(
os.path.dirname(__file__),
'screenshots',
dir_name,
name
)
with open(path, 'rb') as image_file:
encoded_string = base64.b64encode(image_file.read())
return "data:image/png;base64," + encoded_string.decode('ascii')
# Define the app
app = dash.Dash(__name__)
app.layout = html.Div([
# represents the URL bar, doesn't render anything
dcc.Location(id='url', refresh=False),
# content will be rendered in this element
html.Div(id='page-content')
])
@app.callback(dash.dependencies.Output('page-content', 'children'),
[dash.dependencies.Input('url', 'pathname')])
def display_image(pathname): # pylint: disable=W0612
"""
Assign the url path to return the image it represent. For example,
to return "usage.png", you can visit localhost/usage.png.
:param pathname: name of the screenshot, prefixed with "/"
:return: An html.Img object containing the base64 encoded image
"""
if not pathname or pathname == '/':
return None
name = pathname.replace('/', '')
return html.Img(id=name, src=encode(name))
return app
示例6: getLayout
# 需要導入模塊: import dash_core_components [as 別名]
# 或者: from dash_core_components import Location [as 別名]
def getLayout(app):
layout = html.Div([
dcc.Location(id='url', refresh=False),
getHeader(app),
html.Div(id='page-content')
])
return layout