创建一个包含可单击超链接的表 [英] Create a table with clickable hyperlink

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

问题描述

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

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.

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

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

目标是


  1. rederDataTable输出闪亮,以便Google和Yahoo是可点击标签,其链接(Col3)保存在其中。因此,减少3列为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'))


推荐答案

你可以使用 escape 数据表的参数,请参阅 https://rstudio.github.io/DT/#escaping-table-content

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

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

设置 escape = 3 (列号)似乎也可以工作,或者传递 escape 参数 renderDataTable

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

这篇关于创建一个包含可单击超链接的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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