4 Images and Videos
4.1 Images
Images can be displayed using the st.image()
command.
You can use
- local images (e.g. an image on your local drive) by passing a filepath that is relative to where your .py file is.
- note that you will have to make sure that the file is available in the same relative position when you deploy your app.
- e.g.
st.image("resources/cover_image_robot.jpeg")
- web-based images via a URL
- e.g.
st.image("https://upload.wikimedia.org/wikipedia/en/d/d2/Back_to_the_Future.jpg")
- e.g.
Additional parameters allow you to specify
- the image width
- a caption
- whether the image should auto-scale to the width of the page element it is in (e.g. a column)
See details of these options in the documentation here.
4.2 Videos
Videos can be displayed using the st.video()
command.
You can use
- local videos (e.g. a video file on your local drive) by passing a filepath that is relative to where your .py file is.
- note that you will have to make sure that the file is available in the same relative position when you deploy your app.
- e.g.
st.video("resources/my_instruction_video.mp4")
- web-based videos via a URL, including those hosted on youtube
- e.g.
st.video("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
- e.g.
Additional parameters allow you to specify
- start time
- end time
- looping
- subtitles
- whether audio should play
- whether the video should automatically play
- whether the video should loop after finishing
See details of these options in the documentation here.