Solution 1
@app.callback(Output('page-content', 'children'),
Input('url', 'search')) # <--- this has changed
def display_page(params):
# e.g. params = '?firstname=John&lastname=Smith&birthyear=1990'
parsed = urllib.parse.urlparse(params)
parsed_dict = urllib.parse.parse_qs(parsed.query)
print(parsed_dict)
# e.g. {'firstname': ['John'], 'lastname': ['Smith'], 'birthyear': ['1990']}
# use parsed_dict below
# ...
return page_content
Solution 2
import urllib.parse
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
@app.callback(Output('page-content', 'children'),
Input('url', 'pathname'))
def display_page(pathname):
if pathname.startswith("my-dash-app"):
# e.g. pathname = '/my-dash-app?firstname=John&lastname=Smith&birthyear=1990'
parsed = urllib.parse.urlparse(pathname)
parsed_dict = urllib.parse.parse_qs(parsed.query)
print(parsed_dict)
# e.g. {'firstname': ['John'], 'lastname': ['Smith'], 'birthyear': ['1990']}
# use parsed_dict below
# ...
return page_content
if __name__ == '__main__':
app.run_server(debug=True)