rclipboard icon indicating copy to clipboard operation
rclipboard copied to clipboard

modal doesn't seem to work

Open mf-rug opened this issue 2 years ago • 1 comments

My understanding of js is very limited and I'm not sure if I get the meaning of modal correctly, but I'm trying to use rclipButton in combination with shinywidget's dropdownButton. Is that a modal? In any case, using rclipButton inside the dropdownButton does not work, modal being FALSE or TRUE.

Reprex:

library(rclipboard)
library(shiny)
library(shinyWidgets)

# The UI
ui <- bootstrapPage(
  
  rclipboardSetup(),
  
  # Add a text input
  textInput("copytext", "Copy this:", "Zlika!"),
  
  # UI ouputs for the copy-to-clipboard buttons
  dropdownButton(
    uiOutput("clip"),
    circle = TRUE, status = "danger",
    icon = icon("cog"), width = "300px",
    tooltip = tooltipOptions(title = "Click to see inputs !")
  ),
  
  # A text input for testing the clipboard content.
  textInput("paste", "Paste here:")
  
)

# The server
server <- function(input, output) {
  
  # Add clipboard buttons
  output$clip <- renderUI({
    rclipButton("clipbtn", "rclipButton Copy", input$copytext, modal = TRUE, icon("clipboard"))
  })
  
}

shinyApp(ui = ui, server = server)

Here there is no copying to the clipboard anymore. Possibly related to this problem with Clipboard.js

mf-rug avatar Mar 16 '22 15:03 mf-rug

Sorry for the late reply.

The UI created by dropdownButton is not a modal (see documentation).

I looked into your example. Setting the modal argument of rclipButton had no effect on the error reported by the web browser, which is happening in bootstrap code. I must say that I have never looked into using rclipbutton with shinywidgets...

I will continue looking,

sbihorel avatar Aug 06 '22 19:08 sbihorel

Ok I think I found something that works for this.

Instead of using the rclipButton(), I'm using the actionButton() that comes with shinyWidgets. That seems to work. Can you see any issues with it? if I'm using that button is rclipboardSetup() necessary?

library(rclipboard)
library(shiny)
library(shinyWidgets)

# The UI
ui <- bootstrapPage(

  rclipboardSetup(),

  # Add a text input
  textInput("copytext", "Copy this:", "Zlika!"),

  # UI ouputs for the copy-to-clipboard buttons
  dropdownButton(
    actionBttn(
      inputId = "clipbtn",
      icon    = icon("clipboard", lib="font-awesome"),
      label = "Copy Text",
      style = "fill",
      color = "danger",
      size = "sm"
    ),
    circle = TRUE, status = "danger",
    icon = icon("cog"), width = "300px",
    tooltip = tooltipOptions(title = "Click to see inputs !")
  ),

  # A text input for testing the clipboard content.
  textInput("paste", "Paste here:")

)

# The server
server <- function(input, output) {

  # Add clipboard buttons
  observeEvent(input$clipbtn, clipr::write_clip(input$copytext))

}

shinyApp(ui = ui, server = server)

john-harrold avatar Nov 12 '22 19:11 john-harrold

My understanding is that clipr::write_clip sent the information to the clipboard of the server the Shiny app is running on. So if the app is deployed on a server, this solution might not work

sbihorel avatar Nov 13 '22 15:11 sbihorel

Ah I see. You're right. I just tested it locally :).

john-harrold avatar Nov 13 '22 17:11 john-harrold