问题描述
我使用Shiny的renderDataTable创建了一个包含一些HTML链接的表。链接不是可单击的,而是按字面意义呈现的:
I created a table containing some HTML links using Shiny's renderDataTable. The links are not clickable, though, instead they render literally:
您有什么想法吗?在将Shiny升级到0.11版本之前,它运行良好。谢谢!
Do you have any idea what could be wrong? It worked fine before upgrading Shiny to the version 0.11... Thanks!
推荐答案
我遇到了同样的问题。如您在注释中所提到的,renderDataTable的 escape = FALSE
选项解决了它。
I had the same problem. The escape = FALSE
option for renderDataTable solved it, as you mentioned in the comments.
此处是具有链接表的应用程序的完整代码。
Here is complete code for an app with a table that has links.
如果这样做,您将希望每个链接基于表中的值都是唯一的。我将此代码移到一个函数中,使其更干净。
If you are doing this, you will want each link to be unique based on a value in the table. I move this code into a function so its cleaner.
#app.R#
library(shiny)
createLink <- function(val) {
sprintf('<a href="https://www.google.com/#q=%s" target="_blank" class="btn btn-primary">Info</a>',val)
}
ui <- fluidPage(
titlePanel("Table with Links!"),
sidebarLayout(
sidebarPanel(
h4("Click the link in the table to see
a google search for the car.")
),
mainPanel(
dataTableOutput('table1')
)
)
)
server <- function(input, output) {
output$table1 <- renderDataTable({
my_table <- cbind(rownames(mtcars), mtcars)
colnames(my_table)[1] <- 'car'
my_table$link <- createLink(my_table$car)
return(my_table)
}, escape = FALSE)
}
shinyApp(ui, server)
这篇关于Shiny Datatable中的可点击链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!