Dash Bootstrap Theme Explorer Library not importing

I’m trying to use this library: Dash Bootstrap Theme Explorer
it styles Plotly Dash apps with a Bootstrap theme but when I try to import it is apparently not recognized
I couldn’t identify the problem…

import dash
from dash import html, dcc
from dash.dependencies import Input, Output
from matplotlib.pyplot import margins
import pandas as pd
import numpy as np
import dash_bootstrap_components as dbc
from app import *
from dash_bootstrap_templates import load_figure_template
 
import plotly.express as px
import plotly.graph_objects as go

load_figure_template(PULSE)

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.PULSE])
server = app.server

Import “dash_bootstrap_templates” could not be resolved

Hi @Luisanches

The issue might be in this line:

load_figure_template(PULSE)

Try changing it to:

load_figure_template("pulse")

What version of dash-bootstrap-templates do you have installed?
Can you try running this minimal example?

import dash_bootstrap_components as dbc
from dash_bootstrap_templates import load_figure_template
import plotly.express as px

df = px.data.gapminder()

# Makes the Bootstrap Themed Plotly templates available
load_figure_template("pulse")

fig = px.scatter(
    df.query("year==2007"),
    x="gdpPercap",
    y="lifeExp",
    size="pop",
    color="continent",
    log_x=True,
    size_max=60,
    template="pulse",  # use the pulse themed figure template
    title="Gapminder 2007: Pulse Theme",
)

app = Dash(__name__, external_stylesheets=[dbc.themes.PULSE])

app.layout = dbc.Container(dcc.Graph(figure=fig, className="m-4"))

if __name__ == "__main__":
    app.run_server(debug=True)

2 Likes

Hi @AnnMarieW, I did what you told me, and I even reinstalled the library, the import now worked after reinstalling but another error occurred:

 from dash import html, dcc, Input, Output, State, callback, clientside_callback, MATCH
ImportError: cannot import name 'Input' from 'dash'

I think there is some conflict between the libraries but I don’t know what to do…

version of dash-bootstrap-templates installed: dash-bootstrap-templates==1.0.7

from dash import html, dcc, Input, Output, State, callback, clientside_callback, MATCH
ImportError: cannot import name 'Input' from 'dash'

It looks like something changed from your old routing in your original post you had Input, Output[, State] importing from dash.dependencies.

What version of dash are you running?

1 Like

This is the version: dash 2.6.2

Hi @Luisanches

You see this error if you run dash < 2.0.0:

ImportError: cannot import name 'Input' from 'dash'

It may be that the app is not actually using the current version of dash. At the beginning of your app, try adding:

import dash
print(dash.__version__)
2 Likes

in fact it returned me this: 1.0.0
So what to do in this case of dash not running in the correct version?

If this is inside an environment, navigate to the virtual environment and you should be able to:

pip install -U dash
1 Like

I did this and it returned this:

Requirement already satisfied, skipping upgrade: typing-extensions>=3.6.4; python_version < "3.8" in /home/sanches/anaconda3/lib/python3.7/site-packages (from importlib-metadata>=3.6.0; python_version < "3.10"->Flask>=1.0.4->dash) (4.3.0)

but when I run the code it didn’t work, still with the same error…

from dash import html, dcc, Input, Output, State, callback, clientside_callback, MATCH
ImportError: cannot import name 'Input' from 'dash'

Did you get an error along the lines of something about pip?

This is the complete error I get:

Traceback (most recent call last):
  File "/home/sanches/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/sanches/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/sanches/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/home/sanches/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/home/sanches/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/home/sanches/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 322, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/home/sanches/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 136, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/home/sanches/.vscode/extensions/ms-python.python-2022.14.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/home/sanches/Área de Trabalho/Data Science/Curso/Projeto1_Sales/project.py", line 8, in <module>
    from dash_bootstrap_templates import load_figure_template
  File "/home/sanches/anaconda3/lib/python3.7/site-packages/dash_bootstrap_templates/__init__.py", line 68, in <module>
    from aio.aio_theme_changer import ThemeChangerAIO, template_from_url
  File "/home/sanches/anaconda3/lib/python3.7/site-packages/aio/__init__.py", line 1, in <module>
    from .aio_theme_switch import ThemeSwitchAIO
  File "/home/sanches/anaconda3/lib/python3.7/site-packages/aio/aio_theme_switch.py", line 1, in <module>
    from dash import html, dcc, Input, Output, State, callback, clientside_callback, MATCH
ImportError: cannot import name 'Input' from 'dash' (/home/sanches/anaconda3/lib/python3.7/site-packages/dash/__init__.py)

I fixed the problem.
I had to uninstall the 3 dash libraries I was using:

pip uninstall dash
pip uninstall dash-bootstrap-templates
pip uninstall dash-bootstrap-templates

and then install again and update:

pip install dash --upgrade
pip install dash-bootstrap-templates --upgrade
pip install dash-bootstrap-templates
pip3 install --upgrade requests

1 Like