rstudio/shiny-gallery

How to render a clickable link inside `ui.output_data_frame`

Closed this issue · 1 comments

I would like to include a clickable link in the cell of ui.output_data_frame. I have tried a few iterations but cannot find anything that works.

  1. Raw text
import pandas as pd
from shiny import App, render, ui


app_ui = ui.page_fluid(
    ui.output_data_frame("data_output")
)


def server(input, output, session):
    # Load the data
    data = pd.DataFrame({
        "id": [1, 2, 3],
        "url": ['https://google.com', 'https://duckduckgo.com', 'https://bing.com']
    })

    @output
    @render.data_frame
    def data_output():
        df = data.copy()
        return df


app = App(app_ui, server)

Screenshot 2023-12-20 at 15 14 48@2x

  1. Use ui.a
    @output
    @render.data_frame
    def data_output():
        df = data.copy()
        df['url'] = df['url'].apply(lambda x: ui.a(x))
        return df

Screenshot 2023-12-20 at 15 16 28@2x

    @output
    @render.data_frame
    def data_output():
        df = data.copy()
        df['url'] = df['url'].apply(lambda x: f'<a href"{x}">click me</a>')
        return df

Screenshot 2023-12-20 at 15 17 31@2x

Apologies, I created this in the wrong repo. I have reposted in the correct repo here: posit-dev/py-shiny#930