Skip to content

Commit 94641ee

Browse files
committed
Add basic panel app to app.py
1 parent 65f0b2a commit 94641ee

3 files changed

Lines changed: 38 additions & 50 deletions

File tree

app/app.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import logging
55
import matplotlib.pyplot as plt
66

7-
# showcase for importing functions from another .py file (in this case from "./app/getGeoDataFrame.py")
8-
from app.getGeoDataFrame import get_GDF
9-
7+
from app.panel import build_panel_app, serve_panel_app
108

119
class App(object):
1210

@@ -19,38 +17,12 @@ def execute(self, data: TrajectoryCollection, config: dict) -> TrajectoryCollect
1917
logging.info(f'Welcome to the {config}')
2018

2119
"""Your app code goes here"""
20+
21+
pn_app = build_panel_app(data)
2222

23-
# showcase injecting App settings (parameter `year`)
24-
data_gdf = get_GDF(data) # translate the TrajectoryCollection to a GeoDataFrame
25-
logging.info(f'Subsetting data for {config["year"]}')
26-
# subset the data to only contain the specified year
27-
if config["year"] in data_gdf.index.year:
28-
result = data_gdf[data_gdf.index.year == config["year"]]
29-
else:
30-
result = None
31-
32-
# showcase creating an artifact
33-
if result is not None:
34-
result.plot(column=data.get_traj_id_col(), alpha=0.5)
35-
plot_file = self.moveapps_io.create_artifacts_file("plot.png")
36-
plt.savefig(plot_file)
37-
logging.info(f'saved plot to {plot_file}')
38-
else:
39-
logging.warning("Nothing to plot")
40-
41-
# showcase accessing auxiliary files
42-
auxiliary_file_a = MoveAppsIo.get_auxiliary_file_path("auxiliary-file-a")
43-
with open(auxiliary_file_a, 'r') as f:
44-
logging.info(f.read())
45-
46-
# Translate the result back to a TrajectoryCollection
47-
if result is not None:
48-
result = TrajectoryCollection(
49-
result,
50-
traj_id_col=data.get_traj_id_col(),
51-
t=data.to_point_gdf().index.name,
52-
crs=data.get_crs()
53-
)
23+
serve_panel_app(pn_app)
24+
25+
logging.info("Panel app running on port 5006")
5426

5527
# return the resulting data for next Apps in the Workflow
56-
return result
28+
return data

app/getGeoDataFrame.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/panel.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import panel as pn
2+
3+
def build_panel_app(data):
4+
pn.extension()
5+
6+
valid_columns = [col for col in data.get_column_names() if not data.to_point_gdf()[col].isna().all()]
7+
col_selector = pn.widgets.Select(name="Select column", options = valid_columns, value=valid_columns[0])
8+
9+
def explore_plot(data, column):
10+
return pn.pane.plot.Folium(data.explore(column=column), min_width=800, min_height=600, sizing_mode="stretch_both")
11+
12+
out_plt = pn.bind(explore_plot, data=data, column=col_selector)
13+
14+
template = pn.template.MaterialTemplate(
15+
site="MoveApps",
16+
title="Testing Panel",
17+
sidebar=[col_selector],
18+
main=[out_plt],
19+
)
20+
21+
return template
22+
23+
def serve_panel_app(template, port=5006):
24+
pn.serve(
25+
template,
26+
start=True,
27+
show=False,
28+
port=port,
29+
address="0.0.0.0",
30+
allow_websocket_origin=["*"]
31+
)

0 commit comments

Comments
 (0)