Skip to content

Commit

Permalink
Add reactR colorpicker input example
Browse files Browse the repository at this point in the history
  • Loading branch information
alandipert committed Apr 19, 2019
1 parent 1ff452f commit 5162b4d
Show file tree
Hide file tree
Showing 9 changed files with 21,614 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 157-reactr-colorpicker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.Rproj.user
*.swp
.Rhistory
8 changes: 8 additions & 0 deletions 157-reactr-colorpicker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This project was extracted from
[react-R/colorpicker-example](https://github.com/react-R/colorpicker-example)

Built JavaScript is checked in. If you ever need to rebuild it, you can do so
with:

1. `yarn install`
1. `yarn run webpack`
54 changes: 54 additions & 0 deletions 157-reactr-colorpicker/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
library(shiny)

capitalize <- function(s) {
gsub("^(.)", perl = TRUE, replacement = '\\U\\1', s)
}

colorpickerInput <- function(inputId,
defaultColor = "#fff",
type = c(
"sketch",
"alpha",
"block",
"chrome",
"circle",
"compact",
"github",
"hue",
"material",
"photoshop",
"slider",
"swatches",
"twitter"
)) {
color <- restoreInput(id = inputId, default = defaultColor)
type <- paste0(capitalize(match.arg(type)), "Picker")
reactR::createReactShinyInput(
inputId,
"colorpicker",
htmltools::htmlDependency(
name = "colorpicker-input",
version = "1.0.0",
src = file.path(getwd(), "js"),
script = "colorpicker.js"
),
color,
list(type = type),
tags$div
)
}

ui <- fluidPage(
titlePanel("reactR Colorpicker Example"),
tags$p("A colorpicker should appear below. You should be able to select colors and see their hex values appear in the text output."),
colorpickerInput("textInput", type = "sketch"),
textOutput("textOutput")
)

server <- function(input, output, session) {
output$textOutput <- renderText({
sprintf("You entered: %s", input$textInput)
})
}

shinyApp(ui, server)
Loading

0 comments on commit 5162b4d

Please sign in to comment.