I am hitting a wall for days now and I am not able to find any working solution. I am using dash with the django-plotly-dash wrapper.
As a start, I will isolate my case from the whole app:
import json
@app.callback(
Output('div-test-output', 'children'),
[Input('trendline-data', 'relayoutData'),
Input('prio-bar-chart','selectedData'),]
)
def update_test_div_sd(relayoutData, selectedData, *args, **kwargs):
selectedData = [i['x'] for i in selectedData['points']] if selectedData else None
rd_raw_from = relayoutData.get('xaxis.range[0]', None)
rd_raw_to = relayoutData.get('xaxis.range[1]', None)
try:
relayoutData_from = datetime.strptime(rd_raw_from,'%Y-%m-%d %H:%M:%S.%f') if rd_raw_from else None
except ValueError:
relayoutData_from = datetime.strptime(rd_raw_from,'%Y-%m-%d') if rd_raw_from else None
try:
relayoutData_to = datetime.strptime(rd_raw_to,'%Y-%m-%d %H:%M:%S.%f') if rd_raw_to else None
except ValueError:
relayoutData_to = datetime.strptime(rd_raw_to,'%Y-%m-%d') if rd_raw_to else None
return relayoutData_from, relayoutData_to, selectedData
The above callback generates endless POST request and does not reneder the Dash App.
If I only keep the selectedData or the relayoutData independently, it works flawlessly in both cases.
Both 'trendline-data' and 'prio-bar-chart' are generated via callbacks, hence I have suppress_callback_exceptions=True which, as I said, works, except for the scenario above.
Maybe there is some more verbose debugging I can make use of to understand what the actual problem is.
I’ve updated to the new release. Unfortunately, nothing has changed at all. Still getting the infinite loop…
I really hoped the mentioned PR will solve my issue - and, indeed, it looked like that.
Any idea what I should do next? Should I just drop my expectation of multiple interactions between dash app elements? So far 1:N works, N:N is the pain…
sorry to hear that. looking at your code, why you need this *args, **kwargs in the function signature? and I’m assuming your output is a div with text string? so the return relayoutData_from, relayoutData_to, selectedData doesn’t look good.
@radupm if you can share your code by a gist link, that would be more helpful to debug.
About the *args, **kwargs, I just add them for the case additional arguments are passed to the callback, so I avoid errors.
As for the return vars, why is that not good? Now I feel I wrongly understood Dash…?! Just want to see text output for debug/dev reasons.
@radupm my bad on the Output, I thought it was in a list, but your case was not.
So it’s OK to do the return like this.
Quick try with the code, can you also share how to configure the setting with django? I got this
File "/Users/byron/code/.venv/dash130/lib/python3.7/site-packages/django/conf/__init__.py", line 64, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
To keep it simple, you may want to pull the demo and replace one of the apps with the gist code I’ve put above. The ORM queries output would need to be replaced with some dummy data. If the expected output is not clear from the code itself, I can update the gist with dummy data as a replacement for the ORM queries.