创建带有可点击超链接的 table

Create a table with clickable hyperlink

我有一个 R 数据框,它显示在 renderDataTable 调用的 RShiny 输出上。但是,我无法实现一个简单的 Java 或 html 标签来帮助我执行以下操作。

示例:(我正在插入 server.ui 代码,考虑到这些参数将设置在 server.ui 末尾。)为了简化只表示 2 行。 我的数据框

Col1     Col2                  Col3
Google   5 lines description   www.google.com
Yahoo    5 lines description   www.yahoo.com

目标是

  1. rederDataTable 输出闪亮,因此 "Google" 和 "Yahoo" 是可点击的标签,它们的链接 (Col3) 保存在其中。因此,将 3 列减少到 2 列。

非常感谢您的帮助和建议。

output$PM_output <- renderDataTable(expr = mydataframe),
                              options = list(autoWidth = T,
                              LengthMenu = c(5, 30, 50),
                              columnDefs = list(list(targets = c(6,7,8,9) - 1,
                              searchable = F)),
                              pageLength = 5,
                              selection = 'multiple'))

您可以对数据表使用 escape 参数,请参阅 https://rstudio.github.io/DT/#escaping-table-content

shinyApp(
    shinyUI(
        fluidPage(
            dataTableOutput('PM_output')
        )
    ),
    shinyServer(function(input, output, session) {
        require(DT)
        dat <- read.table(text="Col1     Col2                  Col3
          Google   '5 lines description'   www.google.com
          Yahoo    '5 lines description'   www.yahoo.com", header=T, strings=F)
        dat$Col3 <- sapply(dat$Col3, function(x) 
            toString(tags$a(href=paste0("http://", x), x)))

        output$PM_output <- renderDataTable(expr = datatable(dat, escape=FALSE),
          options = list(autoWidth = T))
    })
)

设置escape=3(列号)似乎也有效,或者将escape参数传递给renderDataTable