created plotly dash dashboard

This commit is contained in:
shangqian22
2020-09-23 10:33:26 +08:00
parent 59189b379e
commit 1faa5673e3
12 changed files with 6842 additions and 0 deletions
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
from app import *
+46
View File
@@ -0,0 +1,46 @@
import base64
import io
from app import *
def load_data(contents):
content_type, content_string = contents.split(',')
decoded = base64.b64decode(content_string)
try:
if 'csv' in content_type:
# Assume that the user uploaded a CSV file
df = pd.read_csv(io.StringIO(decoded.decode('utf-8')))
df.to_csv('data/test0.csv')
elif 'xls' in content_type:
# Assume that the user uploaded an excel file
df = pd.read_excel(io.BytesIO(decoded))
return('file loaded')
except Exception as e:
print(e)
return('There was an error processing this file.')
layout = html.Div([
html.H1('Upload Data'),
dcc.Upload(
id='upload-data',
children=html.Div([
'Drag or ',
html.A('Select Files')
]),
style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'margin': '10px'}),
html.Div(id='output-data-upload'),
])
@app.callback(Output('output-data-upload', 'children'),
[Input('upload-data', 'contents')])
def update_output(contents):
if contents is not None:
children = load_data(contents)
return(children)
+51
View File
@@ -0,0 +1,51 @@
import plotly.express as px
from app import *
# data
df=pd.read_csv('data/df0.csv',parse_dates=['Date'])
# marks
index_list=list(range(len(df.loc[:,"Date"].dt.strftime('%Y%m').unique())))
date_list=df.loc[:,"Date"].dt.strftime('%Y%m').unique()
colors = {
'background': '#111111',
'text': '#7FDBFF'}
layout = html.Div([
html.H1('Volume and CTN'),
dcc.Graph(id='cubic-with-slider',style={'backgroundColor':'black'}),
dcc.Graph(id='ctn-with-slider'),
dcc.RangeSlider(
id='month-slider',
min=index_list[0],
max=index_list[-1],
step=1,
marks=dict(zip(index_list,date_list)),
value=[index_list[list(date_list).index('202005')],index_list[-1]]),
])
@app.callback(
Output('cubic-with-slider', 'figure'),
Output('ctn-with-slider', 'figure'),
[Input('month-slider', 'value')])
def update_figure(selected_month):
start_time=date_list[selected_month[0]]
end_time=date_list[selected_month[1]]
filtered_df = df.loc[df.loc[:,'Date'] >= pd.to_datetime(start_time,format='%Y%m')]
filtered_df = filtered_df.loc[filtered_df.loc[:,'Date'] <= pd.to_datetime(end_time,format='%Y%m')]
fig_cubic = px.bar(filtered_df, x="Date", y="Cubic",color="Cubic",hover_data=['Daily total cubic','Marking'])
fig_ctn = px.bar(filtered_df, x="Date", y="CTN",color="CTN",hover_data=['Daily total CTN','Marking'])
fig_cubic.update_layout(
plot_bgcolor=colors['background'],
paper_bgcolor=colors['background'],
font_color=colors['text'])
fig_ctn.update_layout(
plot_bgcolor=colors['background'],
paper_bgcolor=colors['background'],
font_color=colors['text'])
return(fig_cubic,fig_ctn)