bow2py
bow2py

Reputation: 51

Insert folium map html code inside a bokeh app

I posted this as a followup question on Include folium in bokeh tabs, and now as a new question as well.

I´m trying to render the raw HTML-code from my folium map, but it´s not working.. Any ideas? :)

div = Div(
    text=map.get_root().render(), 
    width=x, 
    height=y
)

I would much rather be able to render my folium map directly into a bokeh Div object instead of running an Flask app on the side.. I have looked into the possibilities of using an iframe, but there seems to be something off with my code here as well:

div.text = """<iframe srcdoc= """ + map.get_root().render() + """ height=""" + y + """ width=""" + x +"""></iframe>"""

I managed to use a Flask app on the side for the folium map and then use the url as src to my iframe, but then I was having trouble updating the content of that map from my bokeh tool.

Feel free to comment on anything of the above, cheers! :)

Update - Testscript:

from bokeh.models.widgets import Div
from bokeh.layouts import row
from bokeh.plotting import curdoc
import folium


def run():
    folium_map = folium.Map(location=(60., 20.))

    div = Div(
        text=folium_map._repr_html_(),
        width=500,
        height=500,
    )

    return row(div)

bokeh_layout = run()
doc = curdoc()
doc.add_root(bokeh_layout)

Upvotes: 1

Views: 1041

Answers (1)

Pierre-Loic
Pierre-Loic

Reputation: 1554

With map.get_root().render(), you have all the HTML page. If you just want an iframe, you can use the method _repr_html_() of the folium map :

div = Div(
    text=map._repr_html_(), 
    width=x, 
    height=y
)

Upvotes: 2

Related Questions