I am trying to add clickable hyperlink to a rendered dataframe in Shiny for Python. This is what I tried:
@render.data_frame
def output_df():
IDs = input.IDs()
filtered_df = df[df['ID'].isin(IDs)]
filtered_df['Link'] = [f"""<td> <a href="https://myserver.com/details?synonym={i}"> <div style="height:100%;width:100%"> {i} </div> </a> </td>""" for i in filtered_df['Link']]
return filtered_df
But it doesn't work. Does anyone know exactly how to do it?
You can use ui.HTML
here:
from shiny import ui, render, App
import pandas as pd
df = pd.DataFrame({"Tag": ["python", "py-shiny"]})
app_ui = ui.page_fluid(
ui.output_data_frame("my_df")
)
def server(input, output, session):
@render.data_frame
def my_df():
df["Link"] = [
ui.HTML(f"""<a href='https://stackoverflow.com/questions/tagged/{tag}'
target='_blank'>Link to SO {tag} questions</a>""")
for tag in df["Tag"]
]
return render.DataGrid(df)
app = App(app_ui, server)