Clickable Link

Hi Team,

I have a month column in a dataframe. It is a normal column.
I want to make this a clickable column so that if someone clicks on it , I want to load a corresponding data.

Can someone help me with this.

Regards,
Hari

Hi @HariGan,

Your looking to create buttons, whose names are the titles of your columns in a pandas dataframe, and then when someone clicks the buttons it loads that columns data into a graph or something similar?

I think that the best way to do this is to actually use a selectbox dropdown menu!

import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

st.title("Pandas Dataframe selection")

data = pd.read_csv('trial_df.csv')
data

column_names = list(data.columns)

select = st.selectbox("Choose your data", column_names)

st.write("Your selection",select)

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

plt.hist(select)

st.write(fig)

that gives:

Happy Streamlit-ing!
Marisa

1 Like

Hey @HariGan ,

You might want to look into this, Complete Bokeh DataTable Example using streamlit-bokeh-events
Also, if you want to actually add a hyperlink that routes to some other page you can look into this answer,
Make Streamlit table results hyperlinks or add radio buttons to table? - #2 by ash2shukla

Hope it helps !

1 Like

Hi @Marisa_Smith ,

In the same example lets say the SKU column. I have different SKUs and i want each Sku to be a hyperlink and when i click on the specific SKU i want to load data specific to that SKU.

I hope this makes my requirement clear. Can you help me with this.

Regards,
Hari

Hi @HariGan,

Ah I think then @ash2shukla’s answer is what your looking for! You can get the unique values from you pandas database and make a brokeh table that the user can click on from there!

Brokeh is a Streamlit component, these are add-ons/additions that the Streamit community members have made themselves! This one was made by @ash2shukla!!

Here is a link to all the available components: Streamlit Components

To install this component in your environment you can run: pip install streamlit-bokeh-events

Happy Streamlit-ing!
Marisa

1 Like

Hi @Marisa_Smith & @ash2shukla,

Okay guys. I will try it. But let alone this.
If I have a report name lets say XYZ sales report. I want to actually make this XYZ sales report a clickable link or hyperlink and on click this i want to load a different dataframe. Is it possible.

I am able to do it only for actual URLs or website but not to my reqirement.

Regards,
Hari

Hey @HariGan,

With regards to making a hyperlink (using st.markdown("[link](url)") or st.write("[link](url)")) that would point back to your current app and do this I don’t believe this is possible in Streamlit at the moment.

But there are a number of widgets you may want to use to do the same thing here!

The radio buttons like so, st.radio("pick a sales report", ('abc','xyz')), could work if you have multiple sales reports, and you want the user to select xyz sales or abc sales.

If you only have one option to look at, the using a checkbox is probably more suited to your use: st.checkbox("Click here to see xyz sales report")

Another option is to create a Streamlit app for the xyz sales dataframe and its analysis and launch it (on Sharing perhaps) and link to that hyperlink. This would point the user to a different streamlit app, but it would look like a standard hyperlink in your main app: st.write("[Click to open xyz sales report](https://share.streamlit.io/your/app/link)")

Happy Streamlit-ing!
Marisa