What command can I use to add an image to one of the pages of my project made with streamlit? The image is saved on my computer and I would like it to appear for future users who will use my web app.
I tried to add a folder with images in Visual Studio Code and then use image = Image.open('orbitaceleste.png') and st.image(image) but it gave an error “No such file or directory: ‘orbitaceleste.png’”
My code is more or less like this:
st.sidebar.title("Órbitas em Relatividade")
pagina_selecionada = st.sidebar.selectbox("Selecione um tipo de órbita", ['Óbita de corpos celestes', 'Órbita de raios de luz'])
if pagina_selecionada == "Óbita de corpos celestes":
st.title("Particula massiva orbitando um buraco negro com a massa do Sol")
st.write("E se, de repente, o Sol se transformasse em um buraco negro?")
st.write("Para isso, toda sua massa, de 2 $\cdot$ 10$^{30}$ kg (hoje espalhada numa esfera com cerca de 700.000 km de raio), deveria ser comprimida numa região com raio de cerca de 3 km.")
# IMAGE HERE AFTER TEXT
st.subheader("Escolha o valor da posição inicial (em km):")
x0 = st.slider("Escolha entre 3km e 50km",min_value=3.0, max_value=50.0, step = 0.1)
hi @isa.rsn. The code below worked for me. Did you place the image in the folder? In your example code it looks like you try to open the image without path specification. Also checkout the documentation) for further options. Hope this helps.
import streamlit as st
from PIL import Image
st.sidebar.title("Órbitas em Relatividade")
pagina_selecionada = st.sidebar.selectbox("Selecione um tipo de órbita", ['Óbita de corpos celestes', 'Órbita de raios de luz'])
if pagina_selecionada == "Óbita de corpos celestes":
st.title("Particula massiva orbitando um buraco negro com a massa do Sol")
st.write("E se, de repente, o Sol se transformasse em um buraco negro?")
st.write("Para isso, toda sua massa, de 2 $\cdot$ 10$^{30}$ kg (hoje espalhada numa esfera com cerca de 700.000 km de raio), deveria ser comprimida numa região com raio de cerca de 3 km.")
# IMAGE HERE AFTER TEXT
st.subheader("Escolha o valor da posição inicial (em km):")
x0 = st.slider("Escolha entre 3km e 50km",min_value=3.0, max_value=50.0, step = 0.1)
image = Image.open('./images/favicon.png')
st.image(image, caption='Escolha entre 3km e 50km')
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.