You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding IFrame or Script Capability to GeoJsonPopup #1362
Currently you can embed a IFrame to Popup. This opens up a lot of possibilities for the popups. For example, you can create interactive visualizations via libraries such as Plotly, retrieve the html code and embed in a IFrame, which can then be added to the map as popups.
This capability does not seem to work with GeoJsonPopup. GeoJsonPopup seems to only read plain text or plain html. Is it possible to have GeoJsonPopup recognize IFrame object or html with javascript in the "fields" of geojson "properties"?
Thanks for your quick reply! What I was curious about was how to use GeoJsonPopup with custom HTML.
I think what you are describing is swapping GeoJsonPopoup with Popup, but I am not sure if you would be able to have multiple popups, e.g., one for each location of your GeoJson.
After some try-and-errors, I think I found a solution to my problem that worked well.
My code is heavily based on this folium tutorial notebook, but instead of only showing a given dataframe column as a pre-defined HTML table, as the tutorial does, I created a new col with my HTML code and displayed only it.
I am sharing some snippets below to help whoever has the same problem in the future:
# .... some code to get the df as in the tutorialdefgetHTML(row):
return"<b> Place: %s </b>"%row["name"]
df["html_to_display"] =df.apply(getHTML, axis=1)
# ...popup=GeoJsonPopup(
# Replaced fields and aliases with my own 'html_to_dsplay' #fields=["name", "medianincome", "change"],#aliases=["State:", "2015 Median Income(USD):", "Median % Change:"],#labels=True,labels=False, fields= ["html_to_display"],
localize=True,
style="background-color: yellow;",
)
g=folium.GeoJson(
df,
popup=popup
).add_to(m)
Activity
joaopalotti commentedon Sep 7, 2020
I am currently with the same question. Any updates @junyan0?
Tyllis commentedon Sep 8, 2020
I found a work around with Plotly. Use plotly.offline.plot function to turn the interactive plot into html. Then you stuff that into this function:
def plot_to_iframe(plot, width, height):
html_string = '''
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
''' + plot + '''
'''
iframe = folium.IFrame(html_string, width=width, height=height)
return iframe
Then you can turn that iframe object into a folium popup: folium.Popup(iframe), which can be attached to the map.
joaopalotti commentedon Sep 8, 2020
Hi Tyllis,
Thanks for your quick reply! What I was curious about was how to use GeoJsonPopup with custom HTML.
I think what you are describing is swapping GeoJsonPopoup with Popup, but I am not sure if you would be able to have multiple popups, e.g., one for each location of your GeoJson.
After some try-and-errors, I think I found a solution to my problem that worked well.
My code is heavily based on this folium tutorial notebook, but instead of only showing a given dataframe column as a pre-defined HTML table, as the tutorial does, I created a new col with my HTML code and displayed only it.
I am sharing some snippets below to help whoever has the same problem in the future:
tarynblack commentedon Sep 8, 2021
@joaopalotti this was exactly what I needed, thank you!