Given this method, how are variables passed from the pure Django app to the Dash app?
Take this for example:
A user is on a page called ‘profile’. This page contains a table with two cols. In col1 there is a company name and in col2 there is a button. Clicking a button will load the dash app connected to a dataframe, filtered by the company associated with that button.
What would be the best approach to passing the ‘company’ name between apps to a place such as server.URL_BASE_PATHNAME = /viz/company? Or accessing the variable in dashapp.
I followed the coding snippets of python, Django & Dash above by user ‘nedned’.
I also followed a similar tutorial on youtube, however, in both instances I received the error in the html “Error loading layout”. Does anybody knows what this would entail? If not then how would I go about tracing the error?
I am trying to use your approach but running in to an error:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django_plotly_dash/dash_wrapper.py", line 67, in get_local_stateless_by_name
raise KeyError("Unable to find stateless DjangoApp called %s"%name)
KeyError: ‘Unable to find stateless DjangoApp called simpleexample’
I’ve created a new Django App (admin_dashboard) within my Django project, so my folder structure looks like this:
I think all that is correct and what I’m missing is the import of my test_chart.py / plotly_apps directory but I’m not entirely sure how/where I put it it?
So you’ve done the first two steps on the configuration page whose link I posted. You should continue on with the other steps; you can skip the live updating part if you’re not using it.
Thank you - I totally misunderstood that step - I thought I was meant to be changing that to include the URLs of my own Django app that is handling my Plotly charts!
Just a heads up for anyone using my example: please refer to the Github code rather than the code in my post, as the Github code has some fixes for handling static assets.
But of course, you should be using a web server to handle to your static assets in production at least
And then the Plotly Django tag gets inserted in to the page with the relevant chart? (If this is possible then name would be set depending on the URL that is visited).
My thinking is that I am designing a site with around 8 chart pages and individual URLs, and rather than creating 8 x html files with the app name hardcoded in each, I want a chart_layout_base.html, and I’d set my charts up as Objects (Chart title, chart description, chart app name (for Django plotly tag) etc
My initial attempt above does not have the desired effect and it just outputs {% plotly_direct name=SearchBehaviour %} as a string instead of the chart
Sounds like your template tag is just inserting the string (possibly also html-escaped). Any reason why you can’t put the plotly_direct tag in the html itself?
Yes I can do that, was just trying to find a more efficient way of having 8 x html pages for my charts (which all have the same attributes - title, about, source, Plotly app name etc).
The chart description etc would then be editable via Django admin rather than hard coding it all in the html.
So I then have one chart_base.html and have tags such as {{ title }}, {{ about }}, {{ plotly_app }}, and the relevant info will be passed to the html tags via view.py
I did also try {{ title | safe }} in the html but that didn’t work either.
The django-plotly-dash tags are the same as any other django ones, so you can do the same things - including pass arguments - to them. Also another possibility is to write your own template tag which can then either invoke one of the dpd ones, or even call the python template tag code directly.
Have been building a Django site (with Plotly charts on some pages) on my local machine and recently uploaded it to PythonAnywhere. All non-plotly pages are loading fine but any of my pages containing Plotly charts are giving me this error. Any ideas?
AttributeError at /charts/chart1/
‘WrappedDash’ object has no attribute ‘_generate_renderer’
Thank you Nedned. Is there an ideal way to call the VIZ or fig1 and fig2 from Django? Let us say I have template that has baseline.html that I want to call teh VIZ (dash).