This is a great example of the use of the new Templates. The only thing I personally would change is the iframe to to <iframe width="100%"… Then it becomes responsive.
I worked a little bit with it in order to add it to awesome-panel.org. I primarely changed to code to update the .object of the HTML pane instead of the HTML pane it self to avoid to much “flickr” on the screen when changing the selection. And then I used the FastGridTemplate that I use at awesome-panel.org. This is already pretty mature. But I have many ideas for improving it.
google_map_viewer
"""In [Discourse 1533]\
(https://discourse.holoviz.org/t/example-of-using-template-with-param-classes/1533) Andrew
showcased this example of using the ReactTemplate with Google Maps
Here it is reproduced using the `FastGridTemplate`
"""
import panel as pn
import param
from application.config import site
from awesome_panel_extensions.frameworks.fast.templates import FastGridTemplate
class GoogleMapViewer(param.Parameterized):
continent = param.ObjectSelector(default='Asia', objects=['Africa', 'Asia', 'Europe'])
country = param.ObjectSelector(default='China', objects=['China', 'Thailand', 'Japan'])
settings_panel = param.Parameter()
map_panel = param.Parameter()
_countries = {'Africa': ['Ghana', 'Togo', 'South Africa', 'Tanzania'],
'Asia' : ['China', 'Thailand', 'Japan'],
'Europe': ['Austria', 'Bulgaria', 'Greece', 'Portugal', 'Switzerland']}
def __init__(self, **params):
super().__init__(**params)
self.settings_panel = pn.Param(self, parameters=["continent", "country"])
self.map_panel=pn.pane.HTML(sizing_mode='stretch_width', height=616, margin=0)
self._update_map()
@param.depends('continent', watch=True)
def _update_countries(self):
countries = self._countries[self.continent]
self.param['country'].objects = countries
self.country = countries[0]
@param.depends('country', watch=True)
def _update_map(self):
iframe = """
<iframe width="100%" height="100%" src="https://maps.google.com/maps?q={country}&z=6&output=embed"
frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>
""".format(country=self.country)
self.map_panel.object = iframe
def view():
pn.config.sizing_mode="stretch_width"
viewer = GoogleMapViewer(name='Google Map Viewer')
template = FastGridTemplate(title="Google Map Viewer", row_height=100)
template.sidebar.append(viewer.settings_panel)
template.main[0:6,:]=viewer.map_panel
return template
if __name__.startswith("bokeh"):
view().servable()