I am developing a map by using panel, bokeh, datashader and holoviews. When I run it with the following command it can be usable by only one user for some time:
panel serve --show --port 5009 touristRouteTurkeyV2.py
and for keeping it long-running
nohup panel serve --show --port 5009 touristRouteTurkeyV2.py &
in both cases, after using a couple of minutes I see the following error and map freezes. And the following error message is represented:
Traceback (most recent call last):
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/tornado/web.py", line 1704, in _execute
result = await result
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/panel/io/server.py", line 214, in get
session = await self.get_session()
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/bokeh/server/views/session_handler.py", line 144, in get_session
session = await self.application_context.create_session_if_needed(session_id, self.request, token)
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/bokeh/server/contexts.py", line 243, in create_session_if_needed
self._application.initialize_document(doc)
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/panel/io/server.py", line 173, in initialize_document
super().initialize_document(doc)
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/bokeh/application/application.py", line 194, in initialize_document
h.modify_document(doc)
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/bokeh/application/handlers/function.py", line 143, in modify_document
self._func(doc)
File "/home/username/anaconda3/envs/py37/lib/python3.7/site-packages/panel/io/server.py", line 78, in _eval_panel
panel = panel()
File "/home/username/turkey/touristRouteTurkeyV2.py", line 79, in run
taxi = NYCTaxiExplorer(name="NYC Taxi Trips")
NameError: name 'NYCTaxiExplorer' is not defined
BOKEH_ALLOW_WS_ORIGIN environment variable is already set to the IP address which we are using to serve and the localhost. That way the project runs initially.
The source code I am trying to run is here:
import holoviews as hv, param, pandas as pd
import panel as pn
import numpy as np
import bokeh
from colorcet import cm
import colorcet
import datashader as ds
from holoviews.operation.datashader import rasterize, shade, spread
from holoviews.element.tiles import StamenTerrain
from holoviews.util.transform import lon_lat_to_easting_northing
from datashader.utils import lnglat_to_meters
from holoviews.element import tiles as hvts
from collections import OrderedDict as odict
hv.extension('bokeh', logo=False)
class NYCTaxiExplorer(param.Parameterized):
usecols = ['konum_x','konum_y','hour',"countryOrigin","il"]
df=pd.read_parquet("yabanciKayitlarIlBilgili.parquet")
koordinatDonusum = lon_lat_to_easting_northing(df["longitude"],df["latitude"])
df["konum_x"], df["konum_y"] = koordinatDonusum[0], koordinatDonusum[1]
df["hour"] = df.time.str[0:2]
df = df[usecols]
countries = df.groupby("countryOrigin")["hour"].count().sort_values(ascending=False).reset_index().iloc[0:10].countryOrigin.values.tolist()
fields= odict([("il","il")])
opts = dict(width=1000,height=600,xaxis=None,yaxis=None,bgcolor='black',show_grid=False)
cmaps = ['fire','bgy','bgyw','bmy','gray','kbc']
maps = ['EsriImagery', 'EsriUSATopo', 'EsriTerrain', 'CartoMidnight', 'StamenWatercolor', 'StamenTonerBackground']
bases = odict([(name, getattr(hvts, name)().relabel(name)) for name in maps])
gopts = hv.opts.Tiles(responsive=True, xaxis=None, yaxis=None, bgcolor='black', show_grid=False)
aggfns = odict([(f.capitalize(),getattr(ds,f)) for f in ['count','sum','min','max','mean','var','std']])
norms = odict(Histogram_Equalization='eq_hist', Linear='linear', Log='log', Cube_root='cbrt')
ulkeler = param.ObjectSelector("USA", objects={c:c for c in countries})
alpha = param.Magnitude(default=0.75, doc="Alpha value for the map opacity")
cmap = param.ObjectSelector(colorcet.palette['fire'], objects={c:colorcet.palette[c] for c in cmaps})
hour = param.Range(default=(0, 24), bounds=(0, 24))
basemap = param.Selector(bases)
spreading = param.Integer(0, bounds=(0, 5))
agg_fn = param.Selector(aggfns)
field = param.Selector(fields)
normalization = param.Selector(norms)
data_opacity = param.Magnitude(1.00)
@param.depends('alpha', 'basemap')
def tiles(self):
return self.basemap.opts(self.gopts).opts(alpha=self.alpha)
@param.depends('field', 'agg_fn')
def aggregator(self):
#field = None if self.field == "counts" else self.field
field = None
return self.agg_fn(field)
@param.depends('ulkeler','hour')
def points(self):
points = hv.Points(self.df.query(" countryOrigin == @self.ulkeler "), kdims=['konum_x', 'konum_y'], vdims=['il','hour'])
if self.hour != (0, 24): points = points.select(hour=self.hour)
return points
def viewable(self,**kwargs):
rasterized = rasterize(hv.DynamicMap(self.points), aggregator=self.aggregator, width=800, height=400)
shaded = shade(rasterized, cmap=self.param.cmap, normalization=self.param.normalization)
spreaded = spread(shaded, px=self.param.spreading, how="add")
dataplot = spreaded.apply.opts(alpha=self.param.data_opacity, show_legend=False)
return hv.DynamicMap(self.tiles) * dataplot
def run():
taxi = NYCTaxiExplorer(name="NYC Taxi Trips")
s=pn.Row(taxi.param, taxi.viewable())
return s
pn.serve(run,port=3000)