Python Plotly Dash Tutorial:
In this video, you will learn how to create a dashboard using the Python Dash Module. We are using VSCode as the IDE and Conda to setup our python environment. We will use a public dataset, in csv format, as our data source, and we'll use Pandas dataframes to read the input file. Finally, we use Plotly to draw the charts to the dashboard.
📁 code repo on Github: https://github.com/TechExpertTutorial...
Related Videos/Playlists:
• Tutorials and Demos
Our channel: / @techexperttutorials
link to subscribe: / @techexperttutorials
Most recent video: • CSharp Async Await Explained: Parallel Pro...
Code:
"""
conda install dash dash-core-components dash-html-components pandas plotly -c conda-forge
python app.py
"""
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
app = dash.Dash()
df = pd.read_csv(
'https://gist.githubusercontent.com/ch... +
'5d1ea79569ed194d432e56108a04d188/raw/' +
'a9f9e8076b837d541398e999dcbac2b2826a81f8/'+
'gdp-life-exp-2007.csv')
app.layout = html.Div([
dcc.Graph(
id='life-exp-vs-gdp',
figure={
'data': [
go.Scatter(
x=df[df['continent'] == i]['gdp per capita'],
y=df[df['continent'] == i]['life expectancy'],
text=df[df['continent'] == i]['country'],
mode='markers',
opacity=0.8,
marker={
'size': 15,
'line': {'width': 0.5, 'color': 'white'}
},
name=i
) for i in df.continent.unique()
],
'layout': go.Layout(
xaxis={'type': 'log', 'title': 'GDP Per Capita'},
yaxis={'title': 'Life Expectancy'},
margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
legend={'x': 0, 'y': 1},
hovermode='closest'
)
}
),
dcc.Dropdown(
options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': u'Montréal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
],
value='MTL'
),
html.Label('Multi-Select Dropdown'),
dcc.Dropdown(
options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': u'Montréal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
],
value=['MTL', 'SF'],
multi=True
)
])
if _name_ == '__main__':
app.run_server()
Информация по комментариям в разработке