sbihorel / rclipboard Goto Github PK
View Code? Open in Web Editor NEWclipboard.js for R/Shiny Applications
License: Other
clipboard.js for R/Shiny Applications
License: Other
It is affected by an issue in the clipboardjs library which has been addressed zenorocha/clipboard.js#468
It is pretty straight forward to update the library and use the new Clipboard constructor, could do it myself
Hi Sébastien, (j'écris en anglais même si j'ai vu que tu étais français)
I recently discovered clipboard.js and I thank you for your work.
I installed rclipboard from CRAN and I ran the minimal example and got an error since clipr package was not installed.
I think README could be updated with library(clipr)
.
Romain
This little example app in the help of rclipButton
:
## Not run
## Not run:
library(rclipboard)
library(shiny)
# The UI
ui <- bootstrapPage(
rclipboardSetup(),
# Add a text input
textInput("copytext", "Copy this:", "Zlika!"),
# UI ouputs for the copy-to-clipboard buttons
uiOutput("clip"),
# 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, icon("clipboard"))
})
}
shinyApp(ui = ui, server = server)
## End(Not run)
throws this error
Warning: Error in ifelse: 'list' object cannot be coerced to type 'logical'
Apparently it is using the icon()
as the modal =
argument, so to fix it, change
rclipButton("clipbtn", "rclipButton Copy", input$copytext, icon("clipboard"))
to
rclipButton("clipbtn", "rclipButton Copy", input$copytext, modal = FALSE, icon("clipboard"))
The function rclipButton wraps around actionButton but the width input for rclipButton doesn't get passed through to actionButton.
Hi, I am using rclipboard in one of my shiny apps which i build using docker. However since updating the package, I get error where the button should be. It works on my mac locally but when i use docker to build my shiny app, there is an error where clipboard button should be. I fixed this by rolling the package's version back to 0.1.3 but I wanted you to be aware of this issue. I think its more of an issue related to Linux OS that the docker image is using instead of docker itself.
The base image that i use for my docker build is rocker/shiny:4.1.1
I want to call the rclipbutton inside a r datatable but it doesnt seem to be rendering it in the table.
library(shiny)
library(RSQLite)
library(data.table)
library(DT)
library(dplyr)
library(rclipboard)
ui <- function(request) {
fluidPage(
DT::dataTableOutput("x1"),
column(
12,
column(3,tags$div(title="forecast", numericInput("budget_input", label = ("Total Forecast"), value = 2))),
column(2, textInput(inputId = "description", label = "Bookmark description", placeholder = "Data Summary")),
column(2, bookmarkButton(id="bookmarkBtn"))),
column(2, actionButton("opt_run", "Run")),
DT::dataTableOutput("urlTable", width = "100%"),
tags$style(type='text/css', "#bookmarkBtn { width:100%; margin-top: 25px;}")
)
}
server <- function(input, output, session) {
con <- dbConnect(RSQLite::SQLite(), "bookmarks.db", overwrite = FALSE)
myBookmarks <- reactiveValues(urlDF = NULL)
observeEvent(input$bookmarkBtn, {
session$doBookmark()
})
observeEvent(input$opt_run, {
cat('HJE')
})
output$x1 <- DT::renderDataTable({
input$opt_run
isolate({
datatable(
df %>% mutate(Current = as.numeric(Current)*(input$budget_input)), selection = 'none', editable = TRUE
)
})
})
if(dbExistsTable(con, "Bookmarks")){
tmpUrlDF <- data.table(dbReadTable(con, "Bookmarks"))
myBookmarks$urlDF <- tmpUrlDF[, Timestamp := as.POSIXct(Timestamp, origin="1970-01-01 00:00")]
} else {
myBookmarks$urlDF <- NULL
}
session$onSessionEnded(function() {
tmpUrlDF <- isolate({myBookmarks$urlDF})
if(!is.null(tmpUrlDF)){
dbWriteTable(con, "Bookmarks", tmpUrlDF, overwrite = TRUE)
}
dbDisconnect(con)
})
setBookmarkExclude(c("bookmarkBtn", "description", "urlTable_cell_clicked", "urlTable_rows_all", "urlTable_rows_current", "urlTable_rows_selected", "urlTable_search", "urlTable_state", "urlTable_row_last_clicked"))
df <- data.table(Channel = c("A", "B","C"),
Current = c("2000", "3000","4000"),
Modified = c("2500", "3500","3000"),
New_Membership = c("450", "650","700"))
onBookmarked(fun=function(url){
if(!url %in% myBookmarks$urlDF$URL){
if(is.null(myBookmarks$urlDF)){
myBookmarks$urlDF <-
unique(
data.table(
Description = input$description,
URL = paste0("<a href='", url, "'>", url, "</a>"),
Share = rclipButton("clipbtn", "rclipButton Copy", url, icon("clipboard")),
Timestamp = Sys.time(),
Session = session$token,
User = Sys.getenv("USERNAME")
),
by = "URL"
)
} else {
myBookmarks$urlDF <-
unique(rbindlist(list(
myBookmarks$urlDF,
data.table(
Description = input$description,
Share = rclipButton("clipbtn", "rclipButton Copy", url, icon("clipboard")),
URL = paste0("<a href='", url, "'>", url, "</a>"),
Timestamp = Sys.time(),
Session = session$token,
User = Sys.getenv("USERNAME")
)
)), by = "URL")
}
}
})
output$urlTable = DT::renderDataTable({
req(myBookmarks$urlDF)
myBookmarks$urlDF[User %in% Sys.getenv("USERNAME")]
}, escape=FALSE)
}
enableBookmarking(store = "url")
shinyApp(ui, server)
Hi,
first of all: your sample code works perfectly well. Now I want to call rclipButton()
inside a modal, so I modified your sample code:
library(shiny)
library(rclipboard)
ui <- bootstrapPage(
rclipboardSetup()
)
server <- function(input, output) {
showModal(modalDialog(
# rclipboardSetup(),
textInput("copytext", "Copy this:", "Zlika!"),
uiOutput("clip"),
textInput("paste", "Paste here:")
))
output$clip <- renderUI({
rclipButton("clipbtn", "rclipButton Copy", input$copytext, icon("clipboard"))
})
}
shinyApp(ui = ui, server = server)
Althought the button shows up, it doesn't copy the copytext to the clipboard.
As you can see I also tried to put rclipboardSetup()
inside the modalDialog
, but this doesn't help.
One of the methods I can think of is as follows, but I still think it's very complicated. Can I provide an encapsulation function, like renderprint(), which can paste a list
library(shiny)
library(rclipboard)
library(purrr)
rclipButtonXXX = function(inputId, label, clipText, icon = NULL, width = NULL, modal = FALSE){
if(is.list(clipText)){
sink(file = 'aa.txt')
print(clipText)
sink()
session_txt = readLines("aa.txt",encoding = "UTF-8") %>% paste(.,collapse ='\n' )
file.remove('aa.txt')
return(return(rclipButton(inputId, label, session_txt, icon, width , modal)))
}else{
error("ssha")
}
}
ui =fluidPage(
rclipboardSetup(),
fluidRow(
uiOutput("runenvirclip"),
verbatimTextOutput("runenvir"))
)
server = function(input, output) {
output$runenvirclip <- renderUI({
rclipButtonXXX("runenvirclip", "environment Copy", sessionInfo(), icon("clipboard"))
})
output$runenvir <- renderPrint({
print(sessionInfo())
})
}
shinyApp(ui = ui, server = server)
Is there an option to switch encoding? E.g. German Umlaute are escaped when using your function. Could you add some functionality to also serve symbols and similar?
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
Hi,
Thank you for writing this neat wrapper
would it be possible to add roxygen comments to your source files?
(or commit them if they exist already)
Hi,
When I tried to install the latest (v0.2.0) version of rclipboard from CRAN, there's a failure with the message object ‘tooltip’ is not exported by 'namespace:bslib'
I'm on bslib
0.4.2 and it seems that bslib introduced tooltip() in 0.5.1
https://github.com/rstudio/bslib/blob/main/NEWS.md#new-features-1
Please consider add version requirement of bslib in your DESCRIPTION file
Line 17 in c0578c2
Hi,
thanks for this nice package.
I have a question regarding the framework.
I realized i can't use clipr on a shiny server to set the clipboard client side - so i found rclipboard.
I just wondered if there may be a function or a way to just put stuff into the clipboard, without the rclipButton itself in the ui - when using e.g. another button, and just use it like the clipr::write_clip("string here") function.
As I have a normal action button with some underlying processing, not just plain text, that in the end should write a string into the users clipboard.
Hope this makes sense for an example
observeEvent(input$Name_Check, {
if (Your_Name = "John") {
clipr::write_clip("John")
} else {clipr::write_clip("Not_John")}
})
Thank you very much
In the example from your README you should point out that clipr::write_clip()
will not work in deployed/hosted shiny apps unless you add the argument allow_non_interactive = TRUE
.
I want to test in my Server function to ensure that rclipboardSetup() has been run in the UI. Is there a way to do this?
In the example from your README you should point out that clipr::write_clip()
will not work in deployed/hosted shiny apps unless you add the argument allow_non_interactive = TRUE
.
```R library(rclipboard) library(shiny)
ui <- bootstrapPage(
rclipboardSetup(),
textInput("copytext", "Copy this:", "Zlika!"),
uiOutput("clip"),
textInput("paste", "Paste here:")
)
server <- function(input, output) {
output$clip <- renderUI({
rclipButton("clipbtn", "rclipButton Copy", input$copytext, icon("clipboard"))
})
observeEvent(input$clipbtn, clipr::write_clip(input$copytext))
}
shinyApp(ui = ui, server = server)
</p>
</details>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.