question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

{% plotly_app name='SimpleExample'%} renders a TypeError issue with Dash 1.11.0

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
GibbsConsultingcommented, Apr 17, 2020

PR #243 merged and released as 1.3.1

1reaction
pallavgcommented, Apr 16, 2020

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.


(base) C:\Users\pgupta6\Desktop\PyCharmProjects\personal-work-repo>pip install -U django-plotly-dash
Collecting django-plotly-dash
  Downloading django_plotly_dash-1.3.0-py3-none-any.whl (44 kB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 44 kB 550 kB/s
Collecting Django<3,>=2
  Downloading Django-2.2.12-py3-none-any.whl (7.5 MB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 7.5 MB 1.1 MB/s
Requirement already satisfied, skipping upgrade: plotly in c:\anaconda3\lib\site-packages (from django-plotly-dash) (4.6.0)
Requirement already satisfied, skipping upgrade: Flask>=1.0.2 in c:\anaconda3\lib\site-packages (from django-plotly-dash) (1.1.2)
Requirement already satisfied, skipping upgrade: dpd-components in c:\anaconda3\lib\site-packages (from django-plotly-dash) (0.1.0)
Requirement already satisfied, skipping upgrade: dash-renderer in c:\anaconda3\lib\site-packages (from django-plotly-dash) (1.3.0)
Requirement already satisfied, skipping upgrade: dash-core-components in c:\anaconda3\lib\site-packages (from django-plotly-dash) (1.9.0)
Processing c:\users\pgupta6\appdata\local\pip\cache\wheels\96\99\b7\dd0abccbf36509041224628ed0f3ea1f82c59100437eb71370\dash-1.10.0-cp37-none-any.whl
Requirement already satisfied, skipping upgrade: dash-html-components in c:\anaconda3\lib\site-packages (from django-plotly-dash) (1.0.3)
Requirement already satisfied, skipping upgrade: sqlparse in c:\anaconda3\lib\site-packages (from Django<3,>=2->django-plotly-dash) (0.3.1)
Requirement already satisfied, skipping upgrade: pytz in c:\anaconda3\lib\site-packages (from Django<3,>=2->django-plotly-dash) (2019.3)
Requirement already satisfied, skipping upgrade: six in c:\anaconda3\lib\site-packages (from plotly->django-plotly-dash) (1.14.0)
Requirement already satisfied, skipping upgrade: retrying>=1.3.3 in c:\anaconda3\lib\site-packages (from plotly->django-plotly-dash) (1.3.3)
Requirement already satisfied, skipping upgrade: itsdangerous>=0.24 in c:\anaconda3\lib\site-packages (from Flask>=1.0.2->django-plotly-dash) (1.1.0)
Requirement already satisfied, skipping upgrade: click>=5.1 in c:\anaconda3\lib\site-packages (from Flask>=1.0.2->django-plotly-dash) (7.1.1)
Requirement already satisfied, skipping upgrade: Werkzeug>=0.15 in c:\anaconda3\lib\site-packages (from Flask>=1.0.2->django-plotly-dash) (1.0.1)
Requirement already satisfied, skipping upgrade: Jinja2>=2.10.1 in c:\anaconda3\lib\site-packages (from Flask>=1.0.2->django-plotly-dash) (2.11.2)
Requirement already satisfied, skipping upgrade: dash-table==4.6.2 in c:\anaconda3\lib\site-packages (from dash<1.11->django-plotly-dash) (4.6.2)
Requirement already satisfied, skipping upgrade: future in c:\anaconda3\lib\site-packages (from dash<1.11->django-plotly-dash) (0.18.2)
Requirement already satisfied, skipping upgrade: flask-compress in c:\anaconda3\lib\site-packages (from dash<1.11->django-plotly-dash) (1.4.0)
Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in c:\anaconda3\lib\site-packages (from Jinja2>=2.10.1->Flask>=1.0.2->django-plotly-dash) (1.1.1)
Installing collected packages: Django, dash, django-plotly-dash
  Attempting uninstall: Django
    Found existing installation: Django 3.0.5
    Uninstalling Django-3.0.5:
      Successfully uninstalled Django-3.0.5
  Attempting uninstall: django-plotly-dash
    Found existing installation: django-plotly-dash 1.1.5
    Uninstalling django-plotly-dash-1.1.5:
      Successfully uninstalled django-plotly-dash-1.1.5
Successfully installed Django-2.2.12 dash-1.10.0 django-plotly-dash-1.3.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting App Deployment Errors - Dash Python
This troubleshooting guide describes errors that you may encounter when deploying apps to Dash Enterprise as well as steps to resolve them.
Read more >
What to do when pip dependency resolver wants to use ...
The simplest way to solve this issue is to install the compatible dash vision that is greater than 1.11 and less than 1.21.0....
Read more >
Deploying Dash by Plotly App on render
Has anyone had any success in trying to deploy a Plotly Dash App using render? Dash is based on flask so presumably some...
Read more >
Build and Deploy your Multipage App with Dash Plotly
Learn to create and deploy your Dash Plotly app to the web with a step-by-step downloadable guide in Python. Together we will create...
Read more >
5 challenges using Plotly Dash for web apps | Analytics Vidhya
Dash resolves this issue by storing the data in hidden elements on the ... for the case above would have been a Python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found