Open GarderesG opened 1 year ago
@GarderesG this is not an uncommon issue - in general passing the name (or some other label/tag) of the data to the Dash app through the template, and then using standard Django functionality to access the data inside the callback, is a common use case IMHO.
This means that the real question is what is the best way of making that data available. This depends a lot on your application but in general putting something into a cache using other Django views (eg the one with the template in is usually good; refreshing the app page then repopulates the cache) or mechanism (eg a timer with celery) seems to work well.
You probably don't want to do too much work during a callback, but at the same time if the data is relatively cheap you could have the 'get from cache or repopulate it' logic inside the callback if external population is a step too far.
Thank you for your reply @delsim. Could you point me in the right direction to implement the 'get from cache or repopulate it' logic? I do not have a huge experience with Django, and I have had trouble finding relevant information about it. Would love to get more details :)
I have a Django app aiming to track my stock portfolio daily value (Time Series 1) and daily return (Time Series 2). These 2 Time Series are computed in Django based on custom models and methods (
ts_value
andts_ret
).views.py
On my homepage, I want to display these Time Series in a Dash app with 2 buttons: "Returns" and "Prices". Depending on the button pressed, only one of the 2 time series will be plotted.
dash_app.py
My issue is that I can't pass the time series objects (not even one of the 2) through initial_argument parameter in the HTML template of my homepage (I also tried with
ts_value.to_json()
or directly a Graph object instead ofts_value
in the context, but was not successful).home.html
What could be the best way to do this?