Rshiny-如何使用可点击超链接创建表 [英] Rshiny- How to create a table with clickable hyperlink

查看:826
本文介绍了Rshiny-如何使用可点击超链接创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



示例:(我正在插入server.ui代码,考虑到这些参数要设置在server.ui结束。)为简化代表只有2行。
mydataframe

  Col1 Col2 Col3 
Google 5行描述www.google.com
雅虎5行描述www.yahoo.com

目标是


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

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


$ b $
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/#

  shinyApp(
shinyUI(
fluidPage
dataTableOutput('PM_output')

),
ShinyServer(function(input,ou tput,session){
require(DT)
dat < - read.table(text =Col1 Col2 Col3
Google'5行描述'www.google.com
Yahoo'5行描述'www.yahoo.com',header = T,strings = F)
dat $ Col3< - sapply(dat $ Col3,function(x)
toString(tags $ a (href = paste0(http://,x),x)))

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

设置 escape = 3 (列号)也似乎工作,或者将转义参数传递给 renderDataTable


I have an R data frame, which is displayed on RShiny output called by renderDataTable. However, I am unable to implement a simple Java or html tags that helps me to do the following.

Example: (I am inserting the server.ui code, considering that these parameters are to be set at server.ui end. ) For simplification representing only 2 rows. mydataframe

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

Goal is to

  1. rederDataTable output on shiny so that, "Google" and "Yahoo" are clickable labels, with their links (Colm 3) saved into them. Thereby, reducing 3 columns to 2.

Your help and suggestions are highly appreciated.

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'))

解决方案

You can use the escape argument to datatables, see https://rstudio.github.io/DT/#.

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))
    })
)

setting escape=3 (the column number) also seems to work, or passing escape argument to renderDataTable.

这篇关于Rshiny-如何使用可点击超链接创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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