-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
308 additions
and
17 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 |
---|---|---|
|
@@ -14,5 +14,8 @@ Imports: | |
R6, | ||
V8, | ||
stringi, | ||
htmltools | ||
htmltools, | ||
shiny, | ||
miniUI, | ||
shinyWidgets | ||
RoxygenNote: 6.1.0 |
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
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,176 @@ | ||
|
||
#' Color Scale Shiny Gadget | ||
#' | ||
#' Interactively create a color palette from a unique color | ||
#' | ||
#' @param color Hexadecimal string or a name for color. | ||
#' | ||
#' @export | ||
#' | ||
#' @importFrom miniUI miniPage miniContentPanel | ||
#' @importFrom htmltools tags | ||
#' @importFrom shiny uiOutput renderUI runGadget paneViewer actionButton | ||
#' sliderInput splitLayout icon dialogViewer stopApp observeEvent | ||
#' @importFrom shinyWidgets spectrumInput chooseSliderSkin | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' | ||
#' if (interactive()) { | ||
#' | ||
#' # Launch the gadget with : | ||
#' color_scale() | ||
#' | ||
#' } | ||
#' | ||
#' } | ||
color_scale <- function(color = "#1D9A6C") { | ||
stopifnot(length(color) == 1) | ||
|
||
ui <- miniPage( | ||
chooseSliderSkin("Modern", color = "#112446"), | ||
# style sheet | ||
tags$link(rel="stylesheet", type="text/css", href="colorscale/styles.css"), | ||
# title | ||
tags$div( | ||
class="gadget-title dreamrs-title-box", | ||
tags$h1(icon("paint-brush"), "Color Scale from one color", class = "dreamrs-title"), | ||
actionButton( | ||
inputId = "close", label = "Close", | ||
class = "btn-sm pull-left" | ||
) | ||
), | ||
# body | ||
miniContentPanel( | ||
padding = 10, | ||
spectrumInput( | ||
inputId = "main_col", | ||
label = "Choose a color:", | ||
selected = color, | ||
options = list( | ||
"show-buttons" = FALSE, | ||
"preferred-format" = "hex", | ||
"show-input" = TRUE | ||
) | ||
), | ||
tags$br(), | ||
tags$b("Output palette:"), | ||
uiOutput(outputId = "rect_cols"), | ||
tags$br(), | ||
# tags$b("Parameters:"), | ||
splitLayout( | ||
tags$div( | ||
# width = 6, | ||
# tags$p("Dark colors"), | ||
sliderInput( | ||
inputId = "n_dark", | ||
label = "Number of dark colors:", | ||
min = 1, | ||
max = 10, | ||
value = 4, | ||
width = "90%" | ||
), | ||
sliderInput( | ||
inputId = "p_dark", | ||
label = "Percentage of darkness:", | ||
min = 0, | ||
max = 100, | ||
value = 50, | ||
post = "%", | ||
width = "90%" | ||
), | ||
sliderInput( | ||
inputId = "a_dark", | ||
label = "Dark hue angle:", | ||
min = -360, | ||
max = 360, | ||
value = -51, | ||
post = "\u00b0", | ||
width = "90%" | ||
), | ||
sliderInput( | ||
inputId = "s_dark", | ||
label = "Dark colors saturation:", | ||
min = -100, | ||
max = 100, | ||
value = -14, | ||
post = "%", | ||
width = "90%" | ||
) | ||
), | ||
tags$div( | ||
# width = 6, | ||
# tags$p("Light colors"), | ||
sliderInput( | ||
inputId = "n_light", | ||
label = "Number of light colors:", | ||
min = 1, | ||
max = 10, | ||
value = 6, | ||
width = "90%" | ||
), | ||
sliderInput( | ||
inputId = "p_light", | ||
label = "Percentage of lightness:", | ||
min = 0, | ||
max = 100, | ||
value = 80, | ||
post = "%", | ||
width = "90%" | ||
), | ||
sliderInput( | ||
inputId = "a_light", | ||
label = "Light hue angle:", | ||
min = -360, | ||
max = 360, | ||
value = 67, | ||
post = "\u00b0", | ||
width = "90%" | ||
), | ||
sliderInput( | ||
inputId = "s_light", | ||
label = "Light colors saturation:", | ||
min = -100, | ||
max = 100, | ||
value = 20, | ||
post = "%", | ||
width = "90%" | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
|
||
output$rect_cols <- renderUI({ | ||
col <- input$main_col | ||
colors_rect(colors = c( | ||
get_dark_cols( | ||
color = col, | ||
n = input$n_dark, | ||
darkness = input$p_dark / 100, | ||
rotate = input$a_dark, | ||
saturation = input$s_dark / 100 | ||
), | ||
col, | ||
get_light_cols( | ||
color = col, | ||
n = input$n_light, | ||
lightness = input$p_light / 100, | ||
rotate = input$a_light, | ||
saturation = input$s_light / 100 | ||
) | ||
)) | ||
}) | ||
|
||
observeEvent(input$close, stopApp()) | ||
|
||
} | ||
|
||
runGadget(app = ui, server = server, viewer = paneViewer(minHeight = 600)) # minHeight = "maximize" | ||
} | ||
|
||
|
||
|
||
|
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 @@ | ||
#' Adds the content of www to colorscale/ | ||
#' | ||
#' @importFrom shiny addResourcePath | ||
#' | ||
#' @noRd | ||
.onLoad <- function(...) { | ||
shiny::addResourcePath("colorscale", system.file('www', package = "colorscale")) | ||
} |
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
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,58 @@ | ||
|
||
.dreamrs-title-box { | ||
background-color: rgb(16, 34, 70); | ||
height: 45px; | ||
} | ||
|
||
.dreamrs-title { | ||
color: white; | ||
text-align: center; | ||
font-size: 30px; | ||
font-weight: bold; | ||
} | ||
|
||
|
||
.form-group { | ||
margin-bottom: 0 !important; | ||
} | ||
|
||
|
||
|
||
|
||
/* shiny alerts */ | ||
|
||
.shiny-notification-error { | ||
color: #fff !important; | ||
background-color: #d9534f !important; | ||
border: 1px solid #d9534f !important; | ||
} | ||
|
||
.shiny-notification-warning { | ||
color: #fff !important; | ||
background-color: #f39c12 !important; | ||
border: 1px solid #f39c12 !important; | ||
} | ||
|
||
.shiny-notification-message { | ||
color: #fff !important; | ||
background-color: #5cb85c !important; | ||
border: 1px solid #5cb85c !important; | ||
} | ||
|
||
.shiny-notification { | ||
font-size: 120% !important; | ||
font-weight: bold !important; | ||
} | ||
|
||
#shiny-notification-panel { | ||
width: 100% !important; | ||
text-align: center !important; | ||
} | ||
|
||
.shiny-notification-close { | ||
font-size: 26px; | ||
color: #fff; | ||
cursor: pointer; | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.