Selectbox option links to an image

I’m working with wordcloud library to generate word clouds for different newspapers.

I have 4 different word clouds (BBC, DW, etc), which would normally be displayed via st.pyplot() option.

I want to create a drop down menu with a link to each one of these generated word clouds, but I have no idea how to link the generated wordcloud with the respective option in the dropdown menu.

Is there any simple way of doing this?

Hello @rita-milani,

You could perhaps use a python dictionary to link your word clouds to dropdown options.
You could also rely on a succession of if statements, but I find mapping objects to keys cleaner with dictionaries.

In the sample below, you can replace data variables with your word clouds.

import streamlit as st

data1 = [0, 1, 2]
data2 = [2, 1, 0]
data3 = [0, 1, 0]

plots = {
    "First chart": data1,
    "Second chart": data2,
    "Third chart": data3,
}

plot = st.sidebar.selectbox("Select your chart.", list(plots.keys()))

st.line_chart(plots[plot])