0

I'm hoping to insert an rclipboard::rclipButton() into a DataTable in RShiny and am having trouble figuring out how to do it. Have tried the following (based on: Using renderDataTable within renderUi in Shiny):

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]"

Have also tried paste0()'ing the rclipButton() into the DataTable but that just renders as a long string of HTML.

Any suggestions much appreciated!

katie
  • 3
  • 2

1 Answers1

0

Well, rclipButton() call will generate shiny.tag objects, and you need to change it to string so DT can parse it. Then the key is to use escape = F in datatable.

I also rewrite the way to generate the DT table.

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)

enter image description here

lz100
  • 6,990
  • 6
  • 29