Package 'rclipboard'

Title: Shiny/R Wrapper for 'clipboard.js'
Description: Leverages the functionality of 'clipboard.js', a JavaScript library for HMTL5-based copy to clipboard from web pages (see <https://clipboardjs.com> for more information), and provides a reactive copy-to-clipboard UI button component, called 'rclipButton', and a a reactive copy-to-clipboard UI link component, called 'rclipLink', for 'shiny' R applications.
Authors: Sebastien Bihorel
Maintainer: Sebastien Bihorel <[email protected]>
License: MIT + file LICENSE
Version: 0.2.1
Built: 2025-03-10 05:20:00 UTC
Source: https://github.com/sbihorel/rclipboard

Help Index


Include clipboard.js

Description

This will include the clipboard.js in the head tag.

Usage

rclipboardSetup()

Details

Inclusion of clipboard.js will do so only once, since the code is wrapped inside a singleton call.

rclipboardSetup() must be called in the ui function of the Shiny app before a rclipButton is created (typically in the server function)

Value

A shiny::tagList

Author(s)

Sebastien Bihorel

References

https://clipboardjs.com/

See Also

rclipButton


Action button or action link to send information to clipboard

Description

Creates an action button or link that will send user-defined text to the OS clipboard.

Usage

rclipButton(inputId, label, clipText, modal = FALSE, tooltip, placement, options, ...)
rclipLink(inputId, label, clipText, modal = FALSE, ...)

Arguments

inputId

The input slot that will be used to access the value.

label

The contents of the button or link–usually a text label, but you could also use any other HTML, like an image.

clipText

A single scalar character variable to be sent to the clipboard.

modal

A logical flag indicating whether the button will be shown in a modal window (TRUE) or not (NOT).

tooltip

A strip to display in a tooltip (using the bslib package)

placement

The placement of the tooltip relative to the button

options

List of options for the tooltip

...

Additional arguments (e.g. icon or width) passed down to actionButton or actionLink.

Author(s)

Sebastien Bihorel

References

https://clipboardjs.com/

See Also

rclipboardSetup, tooltip

Examples

## 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(
      inputId = "clipbtn", 
      label = "rclipButton Copy", 
      clipText = input$copytext, 
      icon = icon("clipboard"),
      tooltip = "Click me to copy the content of the text field to the clipboard!",
      options = list(delay = list(show = 800, hide = 100), trigger = "hover")
    )
  })
  
}

shinyApp(ui = ui, server = server)

## End(Not run)