Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
52 changes: 52 additions & 0 deletions 157-reactr-colorpicker/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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"
)) {
reactR::createReactShinyInput(
inputId,
"colorpicker",
htmltools::htmlDependency(
name = "colorpicker-input",
version = "1.0.0",
src = file.path(getwd(), "js"),
script = "colorpicker.js"
),
defaultColor,
list(type = paste0(capitalize(match.arg(type)), "Picker")),
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