Python dash_core_components.Location() Examples
The following are 6
code examples of dash_core_components.Location().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dash_core_components
, or try the search function
.
Example #1
Source File: multi_page.py From dash-recipes with MIT License | 6 votes |
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"})
Example #2
Source File: layouts.py From slapdash with MIT License | 6 votes |
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), ] )
Example #3
Source File: views.py From dtale with GNU Lesser General Public License v2.1 | 5 votes |
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
Example #4
Source File: layouts.py From slapdash with MIT License | 5 votes |
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), ] )
Example #5
Source File: test_percy_snapshot.py From dash-cytoscape with MIT License | 5 votes |
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
Example #6
Source File: layout.py From japonicus with MIT License | 5 votes |
def getLayout(app): layout = html.Div([ dcc.Location(id='url', refresh=False), getHeader(app), html.Div(id='page-content') ]) return layout