简体   繁体   English

DataTable 中的 rclipButton R Shiny

[英]rclipButton in DataTable R Shiny

I'm hoping to insert an rclipboard::rclipButton() into a DataTable in RShiny and am having trouble figuring out how to do it.我希望将rclipboard::rclipButton()插入到 RShiny 中的 DataTable 中,但我无法弄清楚如何去做。 Have tried the following (based on: Using renderDataTable within renderUi in Shiny ):已尝试以下操作(基于: 在 Shiny 中的 renderUi 中使用 renderDataTable ):

library(shiny); library(tidyverse); library(rclipboard)
    
ui <- fluidPage(
    mainPanel(
        rclipboardSetup(),
        uiOutput('myTable')
    )
)

server <- function(input, output) {
    output$myTable <- renderUI({
        output$myTable <- renderUI({
            iris <- iris %>% filter(row_number()==1:2)
            iris$button <- rclipButton(
                inputId = "clipbtn",
                label = "Copy",
                clipText = "test",
                icon = icon("clipboard")
            )
            output$aa <- renderDataTable(iris)
            dataTableOutput("aa")  
        })
    })
}

shinyApp(ui, server)

But looks like this: "[object Object]"但看起来像这样: “[object Object]”

Have also tried paste0()'ing the rclipButton() into the DataTable but that just renders as a long string of HTML.还尝试将 rclipButton() rclipButton()到数据表中,但这只是呈现为 HTML 的长字符串。

Any suggestions much appreciated!非常感谢任何建议!

Well, rclipButton() call will generate shiny.tag objects, and you need to change it to string so DT can parse it.那么, rclipButton()调用将生成shiny.tag对象,您需要将其更改为字符串,以便 DT 可以解析它。 Then the key is to use escape = F in datatable.那么关键就是在datatable中使用escape = F

I also rewrite the way to generate the DT table.我也重写了生成DT表的方式。

library(shiny); library(tidyverse); library(rclipboard)

ui <- fluidPage(
    mainPanel(
        rclipboardSetup(),
        DT::dataTableOutput("aa")  
    )
)

server <- function(input, output) {
    output$aa <- DT::renderDataTable({
        iris2 <- iris %>% filter(row_number()==1:2)
        iris2$button <- rclipButton(
            inputId = "clipbtn",
            label = "Copy",
            clipText = "test",
            icon = icon("clipboard")
        ) %>% as.character()
        DT::datatable(iris2, escape = F)
    })
}

shinyApp(ui, server)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM