{% plotly_app name='SimpleExample'%} renders a TypeError issue with Dash 1.11.0
See original GitHub issueWhen I try to render a plot from the tutorial by in my Django website, I get a TypeError. See below my code snippets and a traceback that I get. Iβve been trying to understand where the problem appears but nothing comes into my mind. The error disappears when I remove β{% plotly_app name=βSimpleExampleβ %}β, so I assume itβs related to django-plotly-dash package.
In Urls.py Iβve included the required βpath(βdjango_plotly_dash/β, include(βdjango_plotly_dash.urlsβ))β
simpleexample.py
import dash
import dash_core_components as dcc
import dash_html_components as html
from django_plotly_dash import DjangoDash
app = DjangoDash('SimpleExample') # replaces dash.Dash
app.layout = html.Div([
dcc.RadioItems(
id='dropdown-color',
options=[{'label': c, 'value': c.lower()} for c in ['Red', 'Green', 'Blue']],
value='red'
),
html.Div(id='output-color'),
dcc.RadioItems(
id='dropdown-size',
options=[{'label': i,
'value': j} for i, j in [('L','large'), ('M','medium'), ('S','small')]],
value='medium'
),
html.Div(id='output-size')
])
@app.callback(
dash.dependencies.Output('output-color', 'children'),
[dash.dependencies.Input('dropdown-color', 'value')])
def callback_color(dropdown_value):
return "The selected color is %s." % dropdown_value
@app.callback(
dash.dependencies.Output('output-size', 'children'),
[dash.dependencies.Input('dropdown-color', 'value'),
dash.dependencies.Input('dropdown-size', 'value')])
def callback_size(dropdown_color, dropdown_size):
return "The chosen T-shirt is a %s %s one." %(dropdown_size,
dropdown_color)
welcome.html (I moved that part to base.html when testing to better show the error in the traceback)
{% extends 'base.html' %}
{% load static %}
{% block content %}
{% load plotly_dash %}
<block>
<div>
{% plotly_app name='SimpleExample' ratio=0.45 %}
</div>
</block>
{% endblock %}
views.py
from django.urls import path
from . import views
from home.dash_apps.finished_apps import simpleexample
urlpatterns = [
path('', views.home, name='home')
This is the traceback which I get after placing the content welcome.html in base.html to better identify where the problem lies
Environment: Request Method: GET Request URL: http://127.0.0.1:8000/
Django Version: 3.0
Python Version: 3.7.7
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home.apps.HomeConfig',
'django_plotly_dash.apps.DjangoPlotlyDashConfig',
'channels',
'channels_redis']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template error:
In template C:\Users\milos\statisticsofcorona\templates\base.html, error at line 55
expected string or bytes-like object
45 : <div class="container-fluid">
46 :
47 : <!-- Page Heading -->
48 : <div class="d-sm-flex align-items-center justify-content-between mb-4">
49 : <h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
50 : <a href="#" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Generate Report</a>
51 : </div>
52 : <div class="row">
53 : <div>
54 : {% load plotly_dash %}
55 : {% plotly_app name="SimpleExample" %}
56 : </div>
Traceback (most recent call last):
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\milos\statisticsofcorona\home\views.py", line 29, in home
return render(request, 'base.html', context)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 936, in render
bit = node.render_annotated(context)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 903, in render_annotated
return self.render(context)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\library.py", line 214, in render
_dict = self.func(*resolved_args, **resolved_kwargs)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\templatetags\plotly_dash.py", line 76, in plotly_app
da, app = _locate_daapp(name, slug, da, cache_id=cache_id)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\templatetags\plotly_dash.py", line 43, in _locate_daapp
da, app = DashApp.locate_item(name, stateless=True, cache_id=cache_id)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\models.py", line 200, in locate_item
app = dash_app.as_dash_instance(cache_id=cache_id)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 165, in as_dash_instance
return self.do_form_dash_instance(cache_id=cache_id)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 201, in do_form_dash_instance
return self.form_dash_instance(replacements, ndid, base_pathname)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 213, in form_dash_instance
serve_locally=self._serve_locally)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 312, in __init__
**kwargs)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\dash\dash.py", line 355, in __init__
self.init_app()
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\dash\dash.py", line 384, in init_app
@self.server.errorhandler(PreventUpdate)
File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\dash\exceptions.py", line 6, in __init__
super(DashException, self).__init__(dedent(msg).strip())
File "C:\Users\milos\AppData\Local\Programs\Python\Python37\lib\textwrap.py", line 430, in dedent
text = _whitespace_only_re.sub('', text)
Exception Type: TypeError at /
Exception Value: expected string or bytes-like object
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (6 by maintainers)
PR #243 merged and released as 1.3.1
Hmm, it seems like 1.3.0 still has the Django 2.n restriction. I did a
pip install -U django-plotly-dash
and it downgraded Django for me.