rclipboard
rclipboard copied to clipboard
modal doesn't seem to work
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
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,
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)
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
Ah I see. You're right. I just tested it locally :).