knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

shinyCopy2clipboard: Copy Text to Clipboard in shiny apps

Introduction

In this package we use clipboard.js which is a lightweight (3kb) javascript library to copy text to clipboard. Tooltip is also added separately in this package which is outside the scope of this javascript library. With this package you can fetch the value from shiny app on the client and send it to clipboard

Installation

You can install the released version of shinyCopy2clipboard from GitHub with:

# install.packages("remotes")
remotes::install_github("deepanshu88/listendata")

Example

This is a basic example which shows you how to solve a common problem:

library(shiny)
library(shinyCopy2clipboard)

# UI
ui <- fluidPage(

  # Setup
  use_copy(),

  # Text Input 1
  textInput("text", "Enter Your Text"),

  # Copy Button 1
  CopyButton(
    "copybtn",
    "Copy to Clipboard",
    icon = icon("copy"),
    text = "No Text Found",
    class = "btn-primary",
    width = "150px"
  )

)

# Server
server <- function(input, output, session) {

  observe({

    req(input$copybtn)
    CopyButtonUpdate(session,
                     id = "copybtn",
                     label = "Copy to Clipboard",
                     icon = icon("copy"),
                     text = input$text
    )

  })

}

# Run App
shinyApp(ui = ui, server = server)


deepanshu88/shinyCopy2clipboard documentation built on Dec. 19, 2021, 10:08 p.m.