ltj-github / shinyCopy2clipboard

Copy Text to Clipboard in Shiny Apps

Home Page:https://www.listendata.com/2021/03/shinycopy2clipboard-copy-to-clipboard.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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/shinyCopy2clipboard")

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)

Learn More

  1. How to show SVG icon instead of text labelled button
  2. Detailed Example (including modal)

Go to my blog listendata.com to read more about the above two points

About

Copy Text to Clipboard in Shiny Apps

https://www.listendata.com/2021/03/shinycopy2clipboard-copy-to-clipboard.html


Languages

Language:R 85.4%Language:JavaScript 14.6%