Files
cief-dashboard/apps/place.py
T
shangqian22 b3d3cdba23 added ETA
2020-10-15 16:07:34 +08:00

69 lines
2.3 KiB
Python

from app import *
# data
df=pd.read_csv('data/warehouse2.csv',parse_dates=['Date'])
# marks
date_list=df.loc[:,"Date"].dt.strftime('%Y%m').unique()
last_month=(df.loc[:,"Date"].max()+pd.Timedelta(30, unit='D')).strftime('%Y%m')
date_list=np.append(date_list,last_month)
date_index=list(range(len(date_list)))
layout = html.Div([
html.H1('Map'),
html.Div(dcc.Graph(id='output-place')),
dbc.Row([
dbc.Col(
dcc.RangeSlider(
id='input-month',
min=date_index[0],
max=date_index[-1],
step=1,
marks=dict(zip(date_index,date_list)),
value=[date_index[-4],date_index[-1]]
)
),
dbc.Col(
html.Button('Update Information', id='input-update'),
)
])
])
@app.callback(
Output('output-place', 'figure'),
Input('input-update', 'n_clicks'),
State('input-month', 'value')
)
def update_figure(n_clicks,selected_month):
start_date=date_list[selected_month[0]]
start_date=pd.to_datetime(start_date,format='%Y%m')
end_date=date_list[selected_month[1]]
end_date=pd.to_datetime(end_date,format='%Y%m')
filtered_df = df.loc[df.loc[:,'Date'] >= start_date]
filtered_df = filtered_df.loc[filtered_df.loc[:,'Date'] <= end_date]
place_cubic=filtered_df.loc[:,'CBM'].groupby(by=df.loc[:,'Place name']).sum()
place_cubic=pd.DataFrame(place_cubic)
place_cubic.columns=['CBM by place']
place_cubic.reset_index(inplace=True)
filtered_df=pd.merge(filtered_df,place_cubic,how="left")
filtered_df.dropna(subset=['CBM by place'],inplace=True)
fig_place = px.scatter_mapbox(filtered_df, lat="Latitude", lon="Longitude", hover_name="CBM by place", hover_data=["Place name","State name",'CBM by place'], size='CBM by place',color='State name',color_discrete_sequence=px.colors.diverging.Portland, size_max=80, zoom=7, center={'lat':3.4339, 'lon':102.1543})
fig_place.update_layout(
mapbox_style="carto-positron",
margin={"r":0,"t":0,"l":0,"b":0},
# mapbox = {
# 'accesstoken': token,
# 'style': "outdoors",
# 'zoom': 0.7}
)
fig_place.update_layout(
autosize=False,
width=1500,
height=900)
return(fig_place)