How to access template initial_arguments from dash app?
See original GitHub issueFor example I have the template.html:
{% extends "dashboards/base_generic.html" %} {% block content %} {% load plotly_dash %} {% plotly_app name="descriptive" ratio=0.75 initial_arguments='{"vehicle_data":{"make":"{{Make}}","model":"{{Model}}","year":"{{Year}}"}}' %} {% endblock %}
And in dash_app.py I have:
app = DjangoDash(name='descriptive', id='vehicle_data')
Kind of confused what method I would use to access ‘vehicle_data’? Hopefully this is the right usage, new to Django and Dash.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How can I access initial arguments within Django dash?
It seems I was able to send intial_arguments at /django_plotly_dash/app/SimpleExample/initial/dpd-initial-args-f51525f2777a46f4…
Read more >Send initial arguments from a Django view to Dash and read it ...
I have an scatter plot on Dash. This scatterplot takes the values from SQL depending on the input parameter id . After querying...
Read more >Template tags — django-plotly-dash documentation
This tag inserts a DjangoDash app within a page as a responsive iframe element. The tag arguments are: ... At least one of...
Read more >django-plotly-dash Documentation - Read the Docs
Dash application are mapped to Django ones, and an application is embedded into a webpage through the use of a template tag.
Read more >How to Create a Multipage Dash App | by Michael McManus
Now that all the required packages are installed, our first step is to create a Python file call app.py . This file will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Result from me random-walking to the solution. For context, I was trying to access the id of a target in my database in an app that plots astronomical spectra.
Views.py
My
views.py
was already returning a context about, so I just added to it. This set the layers to unpack (dash_context
,target_id
,value
):template.html
In my template I had to pass that new context to the app:
dash_app.py
I did this when I defined the app:
When I defined the layout of the app I passed the target id in as a hidden input. The filler text got immediately overwritten so it’s not the most elegant:
Then I had to pass in the value (the end goal that I wanted to access) in the callback:
Hopefully this is helpful to anyone trying to solve this in the future.
@nikhilnaregal - I also have similar requirement and I wasn’t able to find any solution for passing input from Django to Dash. However I found a workaround - that suits my requirement. Please check if its useful in your case.
views.py
home.html
Now In the actual dash layout file - call django model and iterate thru the query - DOING JUST THIS WILL NOT FIX THE ISSUE (Instead - In the dash layout file use live updates with this method: https://dash.plotly.com/live-updates
example_dash_file.py
This may not be an effective solution, but it served the purpose of what a data feed from django to dash does is cleared in this method.