R Shiny:使用`FluidRow()时生成列中数据的HTML链接

时间:2015-03-10 14:51:38

标签: r shiny

我使用R包Shiny显示表格数据。我希望将一列中的值显示为可用于导航到其他页面的HTML链接。

我该怎么做?

Paul K

1 个答案:

答案 0 :(得分:2)

如果您的某个列中包含链接,则可以向其添加HTML链接标记并将其显示在数据表中:

server <- function(input, output) {
  #create dummy data
  data <- data.frame(links=c("http://www.google.com","http://www.google.com"))
  #add html link tags
  data$links <- paste0("<a href='",data$links,"'>",data$links,"</a>")

  #render datatable
  output$table <- renderDataTable(data,escape=FALSE)
}

ui <- fluidPage(
  fluidRow(dataTableOutput(outputId="table"))
)

shinyApp(ui = ui, server = server)

您需要escape=FALSE中的renderDataTable,因为here

可以转发闪亮的0.11 HTML实体
Added an `escape` argument to `renderDataTable()` to escape the HTML entities
  in the data table for security reasons. This might break tables from previous
  versions of shiny that use raw HTML in the table content, and the old behavior
  can be brought back by `escape = FALSE` if you are aware of the security
  implications. (#627)