首页 > 解决方案 > 在散景应用程序中插入 folium map html 代码

问题描述

我将此作为在散景标签中包含 folium的后续问题发布,现在也作为一个新问题发布。

我正在尝试从我的 folium 地图中呈现原始 HTML 代码,但它不起作用.. 有什么想法吗?:)

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

我宁愿能够将我的 folium 贴图直接渲染到散景 Div 对象中,而不是在旁边运行 Flask 应用程序。我已经研究了使用 iframe 的可能性,但我的代码似乎有问题here还有:

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

我设法在侧边使用 Flask 应用程序来制作 folium 地图,然后将 url 用作 iframe 的 src,但后来我无法从我的散景工具更新该地图的内容。

随意对以上任何内容发表评论,干杯!:)

更新 - 测试脚本:

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)

标签: bokehfolium

解决方案


有了map.get_root().render(),您就拥有了所有的 HTML 页面。如果你只想要一个 iframe,你可以使用_repr_html_()folium map 的方法:

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

推荐阅读