Is it possible to display an html file in streamlit?

I have created an interactive folium map and I have saved it as an html file.

I would like to know whether there is a way to display it in my streamlit app.

Thanks in advance for your help :grinning:

PS: I know that I can directly a folium map through streamlit via folium_static(map).

Hi @Alberto_De_Beneditti, welcome to the Streamlit community! Yes, you can use components.html:

Best,
Randy

2 Likes

Hi @randyzwitch!
I tried with components.html, but instead of showing the interactive folium map I visualize a string containing the name of the file (e.g. map1.html).

You have to provide the content of the html file, not the filename.

2 Likes

Hi everyone,
can you show me please how to provide the content of the html file?I have the same problem.
thanks in advance.

Read the html file and keep it as a string:

import streamlit as st

path_to_html = "./the_html_file_i_wanna_show.html" 

# Read file and keep in variable
with open(path_to_html,'r') as f: 
    html_data = f.read()

## Show in webpage
st.header("Show an external HTML")
st.components.v1.html(html_data,height=200)

2 Likes

Thank you very much!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.