Learn R Programming

rclipboard: clipboard.js for R/Shiny applications

clipboard.js is a super light javascript framework, which provides copy-to-clipboard functionality using HTML5. The simple rclipboard R package is simple and leverages clipboard.js functionality to provide a reactive copy-to-clipboard UI button component, called rclipButton, and a reactive copy-to-clipboard UI link component, called rclipLink, for Shiny R applications.

While rclipButton and rclipLink will work in applications that use native shiny UI constructors, the code below illustrates a marginally more complex example in which a tooltip is displayed when hovering on top of the button thanks to the use of UI constructors from the bslib package.

library(shiny)
library(bslib)
library(rclipboard)

# The UI
ui <- bslib::page_fluid(
  
  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(
      inputId = "clipbtn",
      label = "rclipButton Copy",
      clipText = input$copytext, 
      icon = icon("clipboard"),
      tooltip = "Click me... I dare you!",
      placement = "top",
      options = list(delay = list(show = 800, hide = 100), trigger = "hover")
    )
  })
  
}

shinyApp(ui = ui, server = server)

Copy Link

Version

Install

install.packages('rclipboard')

Monthly Downloads

1,649

Version

0.2.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Sebastien Bihorel

Last Published

November 15th, 2023

Functions in rclipboard (0.2.1)

rclipboardSetup

Include clipboard.js
rclipButton

Action button or action link to send information to clipboard