Hey all I am new to Dash/Plotly but am trying to learn on my free time. I am having trouble figuring out how I can control the labels on my figure. I was able to change the label when my drop down input changes, but I can only get it to display the options “value” rather than the “label”. For instance my label reads ‘positive’ rather than ‘Positive Covid-19 Cases’ It seems like it should be something very easy to do but I can’t seem to figure it out. Thanks!`
import pandas as pd
import plotly.express as px
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
covid_data = pd.read_csv(r'https://api.covidtracking.com/v1/states/current.csv')
app.layout = html.Div([
html.H1("Current Covid-19 Data in the United States", style={'text-align': 'center'}),
dcc.Dropdown(id="slct_cat",
options=[
{"label": "Positive Covid-19 Cases", "value": 'positive'},
{"label": "Currently Hospitalized", "value": 'hospitalizedCurrently'},
{"label": "Total Test Taken", "value": 'totalTestResults'}],
multi=False,
value='positive',
style={'width': "40%"}
),
html.Div(id='output_container', children=[]),
html.Br(),
dcc.Graph(id='covid_map', figure={})
])
@app.callback(
[Output(component_id='output_container', component_property='children'),
Output(component_id='covid_map', component_property='figure')],
[Input(component_id='slct_cat', component_property='value')]
)
def update_graph(option_slctd):
print(option_slctd)
print(type(option_slctd))
container = f'{option_slctd} in the US'
dff = covid_data.copy()
fig = px.choropleth(
data_frame=dff,
locationmode='USA-states',
locations='state',
scope="usa",
color=option_slctd,
hover_data=['state', option_slctd],
color_continuous_scale=px.colors.sequential.YlOrRd,
labels={option_slctd: option_slctd},
template='plotly_dark'
)
return container,fig
if __name__ == '__main__':
app.run_server(debug=True)