I am working on a dashboard where I have created multiple plots and I want use a single download button to download all the plots. I am kind of new to dash so any help will be appreciated.
Here is the code snippet for the callback func:
@app.callback(
Output(‘daily_vehicle_cadence’, ‘figure’),
Output(“loading-output-2”, “children”),
Input(‘cadence_line_selection’, ‘value’),
Input(‘cadence_day_type_selection’, ‘value’),
)
def plot_daily_vehicle_cadence(selected_line, selected_day):
if selected_line is None or selected_day is None:
return dash.no_update
fig = plot_functions.daily_vehicle_cadence(city=city, selected_line=selected_line, selected_day=selected_day)
return fig, None
@app.callback(
Output(‘daily_loading_time’, ‘figure’),
Input(‘loading_time_day_type_selection’, ‘value’),
)
def plot_daily_loading_time(selected_day):
if selected_day is None:
return dash.no_update
fig = plot_functions.daily_loading_time(city=city, selected_day=selected_day)
return fig
@app.callback(
Output('daily_worst_case_temp', 'figure'),
# Input('Temp_selection', 'value'),
Input('Temp_day_type_selection', 'value'),
)
def plot_daily_worst_temperature(selected_day):
if selected_day is None:
return dash.no_update
fig = plot_functions.worst_case_charging(city=city, selected_day=selected_day)
return fig
@app.callback(
Output(‘power’, ‘figure’),
Output(‘display_temperature’, ‘children’),
Output(‘display_temperature’,‘value’),
Input(‘power_selection’, ‘value’),
Input(‘display_temperature’, ‘n_clicks’),
State(‘display_temperature’, ‘children’),
State(‘display_temperature’, ‘value’)
)
def plot_daily_power(power_selection, change_temperature_display, temperature_text,button_state):
# if and ONLY if temperature button has been pushed changed display text to opposite
if change_temperature_display is not None and (change_temperature_display != int(button_state)):
button_state = str(change_temperature_display)
if temperature_text == ‘Hide Temperature Plot’:
temperature_text = ‘Show Temperature Plot’
elif temperature_text == ‘Show Temperature Plot’:
temperature_text = ‘Hide Temperature Plot’
# set the enable flag based on user selection
if temperature_text == ‘Hide Temperature Plot’:
# user wants to see temperature plot since button hasn’t been pushed to hide the plot
enable_temperature = True
elif temperature_text == ‘Show Temperature Plot’:
# user wants to hide temperature plot since button hasn’t been pushed to show the plot
enable_temperature = False
if power_selection is None:
return dash.no_update
else:
fig = plot_functions.power_and_average_temperature(city=city, selected_power_type=power_selection,
enable_temperature=enable_temperature)
return fig, temperature_text, button_state
and here is the callback func trying to download them using a single button ( I dont know what to put in return) :
@app.callback(
Output(“download-component”, “data”),
Input(‘download_all’, ‘n_clicks’),
State(‘daily_vehicle_cadence’, ‘figure’),
State(‘daily_loading_time’, ‘figure’),
State(‘daily_worst_case_temp’, ‘figure’),
State(‘power’, ‘figure’),
prevent_initial_call=True,
)
def plot_nnc(n_clicks, figs1, figs2, figs3, figs4):
if n_clicks is None:
raise dash.exceptions.PreventUpdate
else:
return figs1, figs2, figs3, figs4
Please can anyone help me with this.
The error that I am getting is :
Failed component prop type: Invalid component prop data
key data
supplied to Download.
Bad object: {
“data”: ,
“layout”: {
“shapes”: [
{
“fillcolor”: “RoyalBlue”,
“type”: “rect”,
“x0”: 18360,
“x1”: 20160,
“y0”: 0,
“y1”: 30
},
{
“fillcolor”: “RoyalBlue”,
“type”: “rect”,
“x0”: 20160,
“x1”: 21960,
“y0”: 0,
“y1”: 30
}, and so on…