-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reactR colorpicker input example
- Loading branch information
1 parent
1ff452f
commit 5162b4d
Showing
9 changed files
with
21,614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.Rproj.user | ||
*.swp | ||
.Rhistory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.