I have tried 3 tutorials and when I try the first file the imports error, I am now trying the step by step tutorial on the dash site/docs ( Part 2. Layout | Dash for Python Documentation | Plotly ) and when i follow the exact instructions the imports dont work. I have seen similiar problems on google/stack and everyone seems to say its due to dash.py, or some file naming issue, i opened 1 file in VS Code and copied and pasted the code straight from the dash tutorial on their site and it doesnt work. The instructions were create file app.py and copy and paste this code in below and run python app.py and all it does is error on the imports… unresolved import 'dash_core_components" unresolved imports 'dash_html_components" and unresolved imports plotly… I have tried 6 times to install, un install, in 3 different environments, trying 3 diffrent turorials and the same problem every time. I have been using python for a long time and not sure why this is happening but I only have 1 file in vs code named app.py…
-- coding: utf-8 --
Run this app with python app.py
and
visit http://127.0.0.1:8050/ in your web browser.
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
app = dash.Dash(name, external_stylesheets=external_stylesheets)
assume you have a “long-form” data frame
see Plotly Express Arguments | Python | Plotly for more options
df = pd.DataFrame({
“Fruit”: [“Apples”, “Oranges”, “Bananas”, “Apples”, “Oranges”, “Bananas”],
“Amount”: [4, 1, 2, 2, 4, 5],
“City”: [“SF”, “SF”, “SF”, “Montreal”, “Montreal”, “Montreal”]
})
fig = px.bar(df, x=“Fruit”, y=“Amount”, color=“City”, barmode=“group”)
app.layout = html.Div(children=[
html.H1(children=‘Hello Dash’),
html.Div(children='''
Dash: A web application framework for Python.
'''),
dcc.Graph(
id='example-graph',
figure=fig
)
])
if name == ‘main’:
app.run_server(debug=True)