✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

How to pass a url value to update the default selection in a dcc dropdown?


How do I use a parsed value from a url to get the default selection value in a dropdown component. I have tried the following, but it doesn’t work:

Import libraries

import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table as dt
import pandas as pd
import plotly.graph_objs as go

from app import app

df_assoc_details = pd.read_csv(’.associate_details.csv’)

layout = html.Div([
html.Div(html.H1(‘Associate Details’), id = ‘heading’),
options = [{‘label’:i, ‘value’:i} for i in df_assoc_details[‘Associate Name’]],
placeholder = “Select an associate”,
searchable = True


dash.dependencies.Output(‘associate-name’, ‘value’),
[dash.dependencies.Input(‘url’, ‘pathname’)])
def display_page(pathname):
assoc_name = pathname.split(’/’)[-1]
assoc_name = ’ ‘.join(assoc_name.split(’%20’))
return assoc_name

The url looks something like: http://localhost:8050/My%20Name. I would like ‘My Name’ to be the default selection value in the dropdown.