Hello, I’m trying to serve a panel app behind NGINX, but I unfortunately run into the following error when I put any Markdown panes into my panel app:
#!/usr/bin/env python
# coding: utf-8
# In[9]:
import socket
import pyfesom2 as pf
import cartopy.crs as ccrs
import numpy as np
import geoviews as gv
from holoviews.operation.datashader import rasterize, datashade
import pandas as pd
import panel as pn
import holoviews as hv
import os
hv.extension("bokeh")
def plot_mesh(mesh_path):
a, b, g = [0, 0, 0]
if os.path.isfile(f"{mesh_path}/abg.dat"):
with open(f"{mesh_path}/abg.dat") as abg:
a, b, g = [int(x) for x in abg.readlines()[0].strip().split(",")]
mesh = pf.load_mesh(
mesh_path,
abg=[a, b, g],
usepickle=False,
)
title = "Fesom Resolution (NUM_2D_NODES 2d Nodes)"
if os.path.isfile(mesh_path + "/title.txt"):
with open(mesh_path +"/title.txt") as tit_file:
title = tit_file.read().strip()
title = title.replace("NUM_2D_NODES", "{:,}")
node_ids_and_area = np.concatenate(
(
mesh.elem[mesh.no_cyclic_elem],
np.expand_dims(
((2 * mesh.voltri[mesh.no_cyclic_elem]) ** 0.5) / 1000.0, axis=-1
),
),
axis=1,
)
df = pd.DataFrame(node_ids_and_area) #
df.index.name = "Element ID"
df.columns = ["Node 1", "Node 2", "Node 3", "Edge Length"]
# df.head()
nodes = gv.Points((mesh.x2, mesh.y2))
trimesh = gv.TriMesh((df, nodes)).redim(
x="Longitude (˚E)", y="Latitude (˚N)", z="Resolution (m**2)"
)
projection = ccrs.PlateCarree()
projected_trimesh = gv.project(trimesh, projection=projection)
FESOM_Resolution = rasterize(projected_trimesh).opts(
cmap="bgy_r",
projection=projection,
width=800,
height=600,
colorbar=True,
colorbar_position="bottom",
tools=["hover"],
clabel="Resolution as Average Element Edge Length (km)",
bgcolor="darkgray",
color_levels=20,
cformatter="%.0f",
clim=(20, 180),
title=title.format(mesh.n2d),
)
return FESOM_Resolution
meshes = []
for user in os.listdir("/home/csys/"):
if os.path.isdir(f"/home/csys/{user}/public/FESOM_Meshes/"):
for root, dirs, files in os.walk(f"/home/csys/{user}/public/FESOM_Meshes/"):
for dir_ in dirs:
try:
print(f"Tying to load up {root}/{dir_}")
meshes.append((f"{root}/{dir_}", plot_mesh(f"{root}/{dir_}")))
except Exception as e:
print(e)
pass # Error with that mesh...
FESOM_Resolution = pn.Tabs(*meshes)
gs = pn.GridSpec(sizing_mode="stretch_both", max_height=800)
#gs[0, 0] = "# Fesom Mesh Gallery"
gs[1, 0] = FESOM_Resolution
gs[2, 0] = "You may add your own mesh here by placing the mesh folder in `${HOME}/public/FESOM_Meshes/`.\nA comma-seperated file called `abg.dat` in the mesh folder will set the alpha, beta, and gamma values for rotated/non-rotated meshes.\n.A file called `title.txt` will set the mesh title. To include the number of 2d nodes, use the string `NUM_2D_NODES`. It will be replaced automatically."
#gs[3, 0] = "<p style='color=gray'><em>The Fesom Mesh Gallery is maintained by Paul Gierz</em></p>"
gs.servable()
Here’s the minimal NGINX config I’m using. I tried hooking up the static files as described in the Bokeh documentation, but that didn’t work either:
server {
location /meshes {
proxy_pass http://localhost:6001;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_buffering off;
}
#location /static {
# alias /opt/miniconda3/lib/python3.7/site-packages/bokeh/server/static;
#}
}