Shiny Datatable 中的可点击链接 [英] Clickable links in Shiny Datatable

查看:35
本文介绍了Shiny Datatable 中的可点击链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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:

https://samizdat.shinyapps.io/zakazky/

你知道哪里出了问题吗?在将 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 中的可点击链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆