【问题标题】:insert Hyperlink to DT table in Shiny在 Shiny 中插入指向 DT 表的超链接
【发布时间】:2017-10-12 16:02:03
【问题描述】:

我想在闪亮的 DT 表中插入一个超链接。

为了节省加载时间,我想插入指向当前视图的超链接 (input$table_rows_current)。

我已经厌倦了观察,但我不知道如何指定插入超链接的位置以及如何?

非常感谢任何帮助。

这里是示例代码:

library(shiny)

createLink <- function(val) {
   sprintf('<a href="https://www.google.com/#q=%s" target="_blank" >%s</a>',val,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({
        dt <- datatable(mtcars, escape=FALSE, selection = 'none') %>% formatStyle(0, cursor = 'pointer')
      })


     observe({
        List <- input$table1_rows_current
        List <- createLink(List)
         return(List)
     })

}

shinyApp(ui, server)

【问题讨论】:

  • 我有不同的问题......这只是一个例子。我有非常大的数据矩阵,如果我使用这段代码,加载需要 15-20 分钟......所以为了节省时间,我只想在表格中的当前视图中添加超链接。

标签: r shiny dt


【解决方案1】:

createLink 函数不起作用,因为您错过了一个val

更正:

createLink <- function(val,val) {
   sprintf('<a href="https://www.google.com/#q=%s' target="_blank" >%s</a>',val,val)  
}

然后您可以使用 createLink() 如下:

input$table1_rows_current = createLink(input$table1_rows_current,
                                       input$table1_rows_current)

它将显示嵌入的链接列。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-03
    • 2019-07-14
    • 2011-03-29
    • 2014-10-30
    • 2017-05-03
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多