Skip to content

Commit 9ba9eec

Browse files
committed
Add reactR colorpicker input example
1 parent 1ff452f commit 9ba9eec

File tree

10 files changed

+21612
-3
lines changed

10 files changed

+21612
-3
lines changed

157-reactr-colorpicker/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.Rproj.user
3+
*.swp
4+
.Rhistory

157-reactr-colorpicker/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This project was extracted from
2+
[react-R/colorpicker-example](https://github.com/react-R/colorpicker-example)
3+
4+
Built JavaScript is checked in. If you ever need to rebuild it, you can do so
5+
with:
6+
7+
1. `yarn install`
8+
1. `yarn run webpack`

157-reactr-colorpicker/app.R

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
library(shiny)
2+
3+
capitalize <- function(s) {
4+
gsub("^(.)", perl = TRUE, replacement = '\\U\\1', s)
5+
}
6+
7+
colorpickerInput <- function(inputId,
8+
defaultColor = "#fff",
9+
type = c(
10+
"sketch",
11+
"alpha",
12+
"block",
13+
"chrome",
14+
"circle",
15+
"compact",
16+
"github",
17+
"hue",
18+
"material",
19+
"photoshop",
20+
"slider",
21+
"swatches",
22+
"twitter"
23+
)) {
24+
reactR::createReactShinyInput(
25+
inputId,
26+
"colorpicker",
27+
htmltools::htmlDependency(
28+
name = "colorpicker-input",
29+
version = "1.0.0",
30+
src = file.path(getwd(), "js"),
31+
script = "colorpicker.js"
32+
),
33+
defaultColor,
34+
list(type = paste0(capitalize(match.arg(type)), "Picker")),
35+
tags$div
36+
)
37+
}
38+
39+
ui <- fluidPage(
40+
titlePanel("reactR Colorpicker Example"),
41+
tags$p("A colorpicker should appear below. You should be able to select colors and see their hex values appear in the text output."),
42+
colorpickerInput("textInput", type = "sketch"),
43+
textOutput("textOutput")
44+
)
45+
46+
server <- function(input, output, session) {
47+
output$textOutput <- renderText({
48+
sprintf("You entered: %s", input$textInput)
49+
})
50+
}
51+
52+
shinyApp(ui, server)

0 commit comments

Comments
 (0)