I want to convert my dash app callbacks into client-side callbacks so that my app goes faster.
I have already read the Dash Clientside callback documentation.
My problem is that I have huge callbacks and I don’t have knowledge about JavaScript
, so at the moment it’s so difficult for me to apply the conversion.
I was wondering if someone could convert one of my app callbacks and then I will try to convert the rest taking that one as reference:
@app.callback(
dash.dependencies.Output('figures_container', 'children'),
[dash.dependencies.Input('version1_dropdown', 'value'),
dash.dependencies.Input('version2_dropdown', 'value'),
dash.dependencies.Input('lang_dropdown', 'value')])
def version_figures(value1, value2, lang_value):
if(lang_value is None or value1 is None or value2 is None):
return dash.no_update
else:
versions_stats = R.versions_stats
if lang_value == 'Spanish':
if value1 == 'Oct 1st 2016':
entities_version1 = versions_stats[0]
df1 = R.instance_types_es_2016_10_01
if value1 == 'Oct 1st 2020':
entities_version1 = versions_stats[18]
df1 = R.instance_types_es_2020_10_01
if value1 == 'May 1st 2021':
entities_version1 = versions_stats[36]
df1 = R.instance_types_es_2021_05_01
if value1 == 'June 1st 2021':
entities_version1 = versions_stats[54]
df1 = R.instance_types_es_2021_06_01
if value2 == 'Oct 1st 2016':
entities_version2 = versions_stats[0]
df2 = R.instance_types_es_2016_10_01
if value2 == 'Oct 1st 2020':
entities_version2 = versions_stats[18]
df2 = R.instance_types_es_2020_10_01
if value2 == 'May 1st 2021':
entities_version2 = versions_stats[36]
df2 = R.instance_types_es_2021_05_01
if value2 == 'June 1st 2021':
entities_version2 = versions_stats[54]
df2 = R.instance_types_es_2021_06_01
if lang_value == 'English':
if value1 == 'Oct 1st 2016':
entities_version1 = versions_stats[72]
df1 = R.instance_types_en_2016_10_01
if value1 == 'Oct 1st 2020':
entities_version1 = versions_stats[90]
df1 = R.instance_types_en_2020_10_01
if value1 == 'May 1st 2021':
entities_version1 = versions_stats[108]
df1 = R.instance_types_en_2021_05_01
if value1 == 'June 1st 2021':
entities_version1 = versions_stats[126]
df1 = R.instance_types_en_2021_06_01
if value2 == 'Oct 1st 2016':
entities_version2 = versions_stats[72]
df2 = R.instance_types_en_2016_10_01
if value2 == 'Oct 1st 2020':
entities_version2 = versions_stats[90]
df2 = R.instance_types_en_2020_10_01
if value2 == 'May 1st 2021':
entities_version2 = versions_stats[108]
df2 = R.instance_types_en_2021_05_01
if value2 == 'June 1st 2021':
entities_version2 = versions_stats[126]
df2 = R.instance_types_en_2021_06_01
bar_figure = F.get_version_bar_figure([value1, value2], [entities_version1, entities_version2])
pie_figure = F.get_version_pie_figure([value1, value2], [entities_version1, entities_version2])
bar_graph = dcc.Graph(id='versions_bar', figure=bar_figure, style={'height':'26.041666666666668vw', 'width':'45.572916666666664vw', 'display': 'inline-block'})
pie_graph = dcc.Graph(id='versions_pie', figure=pie_figure, style={'height':'19.53125vw', 'width':'45.572916666666664vw', 'display': 'inline-block'})
title = html.H3(value1 + " VS " + value2)
type_title = html.H3("DBpedia types comparison")
types_container = html.Div([
dcc.Graph(id='ontology_version', figure=F.ontology_figure, style={'height':'26.041666666666668vw', 'width':'39.0625vw', 'display': 'inline-block'}),
dcc.Graph(id='instance_types_version', figure=F.get_versions_instance_types_figure([value1, value2], df1, df2),
style={'height':'26.041666666666668vw', 'width':'45.572916666666664vw', 'display': 'inline-block'})
]
)
return title, html.Br(), bar_graph, pie_graph, html.Hr(), type_title, types_container
As you can see, this callback takes items ( dataframes
, lists
, figures
…) from other local modules ( R
, F
…). I don’t know if it is possible to convert callbacks in this context.
Hope you can help me. Thanks in advance.