Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuoran29 committed Dec 23, 2021
2 parents c208f59 + 8e7e053 commit d93a1ad
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions app/apps/site_selection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import app_config
import itertools
import json
import dash
import dash_bootstrap_components as dbc
Expand All @@ -16,6 +17,7 @@
from dash.exceptions import PreventUpdate
from dash_extensions.javascript import arrow_function, assign

import plotly.graph_objects as go
from pathlib import Path

from app import app
Expand Down Expand Up @@ -53,6 +55,13 @@
USER_POINT = 'user_point'
QUERY_STATUS = 'query_status'
LINKS='site-links-section'
POP_GRAPH = 'pop-graph'
POP_FIELDS = []
for i in range(1,6):
POP_FIELDS.append([f'ssp{i}{x}' for x in range(2020,2051,5)])

NEW_INDEX = list(range(2020,2051,5))
SSPS = [f'SSP{x}' for x in range(1,6)]

def get_style(feature):
return dict()
Expand Down Expand Up @@ -132,11 +141,11 @@ def get_d_style(feature):
pop_projections = dl.GeoJSON(
url="/assets/us_county.geojson", # url to geojson file
options=dict(style=style_handle), # how to style each polygon
zoomToBounds=False, # when true, zooms to bounds when data changes (e.g. on load)
zoomToBounds=True, # when true, zooms to bounds when data changes (e.g. on load)
zoomToBoundsOnClick=True, # when true, zooms to bounds of feature (e.g. polygon) on click
hoverStyle=arrow_function(dict(weight=5, color='#666', dashArray='')), # style applied on hover
hideout=dict(colorscale=colorscale, classes=classes, style=style, colorProp="pop_change_percent"),
id="geojson"
id="pop-projections"
)

# # California water use
Expand Down Expand Up @@ -270,8 +279,11 @@ def render_map():
html.H3('Site details:', className='text-success'),
html.Div(id=SITE_DETAILS2),
html.Div(id=LINKS)
],width=3)
],style={'padding':40})
],width=3),
],style={'padding':30}),
dbc.Row([
html.Div(id=POP_GRAPH)
])
]


Expand Down Expand Up @@ -438,6 +450,40 @@ def info_hover(features):
return ['Hover over a feature']


@app.callback(
Output(POP_GRAPH,'children'),
[Input(component_id='pop-projections',component_property='hover_feature')]
)

def plot_pop_projection(feature):
if feature:
## get the info and turn it into a dataframe
pop_df = pd.DataFrame(feature['properties'], index=[0])
ssps = pop_df[POP_FIELDS[0]].transpose()
ssps.rename(columns={ssps.columns[0]: 'SSP1'}, inplace=True)
ssps.index = NEW_INDEX
for i in range(2,6):
tmp = pop_df[POP_FIELDS[i-1]].transpose()
tmp.rename(columns={tmp.columns[0]: f'SSP{i}'}, inplace=True)
tmp.index = NEW_INDEX
ssps = ssps.join(tmp)

print(ssps.head())

## make the graph and return it

fig = go.Figure()
for ssp in SSPS:
fig.add_trace(go.Scatter(
x = list(ssps.index),
y = list(ssps[ssp]),
mode = 'lines',
name = ssp
))
return(dcc.Graph(figure=fig))
else:
return None

external_stylesheets = [dbc.themes.FLATLY]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.title = 'Site Selection (Beta)'
Expand All @@ -447,4 +493,3 @@ def info_hover(features):
if __name__ == '__main__':
app.run_server(debug=False, port=8150)


0 comments on commit d93a1ad

Please sign in to comment.