| 1 |
#' Shiny app to pick colors in HCL space |
| 2 |
#' |
| 3 |
#' The app visualizes colors either along the hue-chroma plane for a given luminance value or along the |
| 4 |
#' luminance-chroma plane for a given hue. Colors can be entered by specifying the hue (H), chroma (C), |
| 5 |
#' and luminance (L) values via sliders, by entering an RGB hex code, or by clicking on a color in the |
| 6 |
#' hue-chroma or luminance-chroma plane. It is also possible to select individual colors and add them |
| 7 |
#' to a palette for comparison and future reference. |
| 8 |
#' |
| 9 |
#' @return \code{hclcolorpicker} invisibly returns a vector of colors choosen. |
| 10 |
#' If no colors have been selected \code{NULL} will be returned. |
| 11 |
#' @examples |
| 12 |
#' \dontrun{ |
| 13 |
#' hclcolorpicker() |
| 14 |
#' } |
| 15 |
#' @export |
| 16 |
#' @importFrom methods as |
| 17 |
#hclcolorpicker <- function() { |
| 18 |
# app <- shiny::shinyApp(ui = color_picker_UI(), server = color_picker_Server()) |
| 19 |
# shiny::runApp(app) |
| 20 |
#} |
| 21 |
|
| 22 |
color_picker_sidebarPanel <- function() { |
| 23 |
|
| 24 |
# sidebar with controls to select the color |
| 25 |
shiny::sidebarPanel( |
| 26 |
shiny::sliderInput("H", "Hue", |
| 27 |
min = 0, max = 360, value = 60), |
| 28 |
shiny::sliderInput("C", "Chroma", |
| 29 |
min = 0, max = 180, value = 40), |
| 30 |
shiny::sliderInput("L", "Luminance", |
| 31 |
min = 0, max = 100, value = 60), |
| 32 |
shiny::splitLayout( |
| 33 |
shiny::textInput("hexcolor", "RGB hex color", colorspace::hex(colorspace::polarLUV(60, 40, 60))), |
| 34 |
shiny::div(class = 'form-group shiny-input-container', |
| 35 |
shiny::actionButton("set_hexcolor", "Set") |
| 36 |
), |
| 37 |
cellWidths = c("70%", "30%"), |
| 38 |
cellArgs = list(style = "vertical-align: bottom;") |
| 39 |
), |
| 40 |
shiny::p(HTML("<b>Selected color</b>")), |
| 41 |
shiny::htmlOutput("colorbox"), |
| 42 |
shiny::withTags(p(style="margin-top: 5px; font-weight: bold;","Actions")), |
| 43 |
shiny::actionButton("color_picker", "Pick"), |
| 44 |
shiny::actionButton("color_unpicker", "Unpick"), |
| 45 |
shiny::actionButton("clear_color_picker", "Clear"), |
| 46 |
# Disable "Return to R" button if running on webserver |
| 47 |
if ( ! Sys.info()["nodename"] == "sculptor.uberspace.de" ) { |
| 48 |
shiny::actionButton("closeapp","Return to R") |
| 49 |
}, |
| 50 |
checkboxInput("darkmode", "Dark mode", value = FALSE, width = NULL) |
| 51 |
|
| 52 |
) |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
color_picker_mainPanel <- function() { |
| 57 |
|
| 58 |
# --------------------------------------------------------------- |
| 59 |
# Main shiny panel |
| 60 |
# --------------------------------------------------------------- |
| 61 |
shiny::mainPanel( |
| 62 |
|
| 63 |
shiny::tabsetPanel(type = "tabs", id = "maintabs", |
| 64 |
# ----------------------------------------------------------- |
| 65 |
# Shinys Luminance-Chroma plane tab |
| 66 |
# ----------------------------------------------------------- |
| 67 |
shiny::tabPanel("Luminance-Chroma plane", value = "lcplane", |
| 68 |
shiny::plotOutput("LC_plot", click = "LC_plot_click"), |
| 69 |
shiny::plotOutput("Hgrad", click = "Hgrad_click", height = 50), |
| 70 |
shiny::plotOutput("Cgrad", click = "Cgrad_click", height = 50), |
| 71 |
shiny::plotOutput("Lgrad", click = "Lgrad_click", height = 50) |
| 72 |
), |
| 73 |
# ----------------------------------------------------------- |
| 74 |
# Shinys Hue-Chroma plane |
| 75 |
# ----------------------------------------------------------- |
| 76 |
shiny::tabPanel("Hue-Chroma plane", value = "hcplane", |
| 77 |
shiny::plotOutput("HC_plot", click = "HC_plot_click"), |
| 78 |
shiny::plotOutput("Hgrad2", click = "Hgrad_click", height = 50), |
| 79 |
shiny::plotOutput("Cgrad2", click = "Cgrad_click", height = 50), |
| 80 |
shiny::plotOutput("Lgrad2", click = "Lgrad_click", height = 50) |
| 81 |
), |
| 82 |
# ----------------------------------------------------------- |
| 83 |
# Export tab |
| 84 |
# ----------------------------------------------------------- |
| 85 |
shiny::tabPanel("Export", value = "export", icon = icon("download", lib = "font-awesome"), |
| 86 |
shiny::withTags(div(class = "hcl", id = "hcl-export", |
| 87 |
withTags(div(class = "output-raw", |
| 88 |
htmlOutput("exportRAW1"), |
| 89 |
downloadButton("downloadRAW1", "Download") |
| 90 |
)), |
| 91 |
withTags(div(class = "output-raw", |
| 92 |
htmlOutput("exportRAW2"), |
| 93 |
downloadButton("downloadRAW2", "Download") |
| 94 |
)), |
| 95 |
withTags(div(class = "output-raw", |
| 96 |
htmlOutput("exportRAW3"), |
| 97 |
downloadButton("downloadRAW3", "Download") |
| 98 |
)), |
| 99 |
withTags(div(class = "output-raw", |
| 100 |
htmlOutput("exportRAW4") |
| 101 |
)), |
| 102 |
withTags(div(class = "end-float")), |
| 103 |
shiny::h3("Output"), |
| 104 |
shiny::htmlOutput("palette_line_R"), |
| 105 |
shiny::htmlOutput("palette_line_matlab") |
| 106 |
)) |
| 107 |
), |
| 108 |
# ----------------------------------------------------------- |
| 109 |
# Info tab |
| 110 |
# ----------------------------------------------------------- |
| 111 |
shiny::tabPanel("Info", value = "info", icon = icon("info-circle", lib = "font-awesome"), |
| 112 |
withTags(div(class = "hcl-main", id = "hcl-main-help", |
| 113 |
includeHTML("html/info.html") |
| 114 |
)) |
| 115 |
) |
| 116 |
), |
| 117 |
withTags(div(class = "end-float")), |
| 118 |
shiny::h3("Color palette"), |
| 119 |
shiny::plotOutput("palette_plot", click = "palette_click", height = 30) |
| 120 |
) |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
# ------------------------------------------------------------------- |
| 125 |
# Setting up the UI |
| 126 |
# ------------------------------------------------------------------- |
| 127 |
shiny::shinyUI( |
| 128 |
fluidPage( |
| 129 |
tags$head( |
| 130 |
tags$link(rel = "stylesheet", type = "text/css", href = "hclcolorpicker.css"), |
| 131 |
tags$link(rel = "stylesheet", type = "text/css", href = "hclcolorpicker_darkmode.css") |
| 132 |
), |
| 133 |
shinyjs::useShinyjs(), |
| 134 |
shiny::div(class = "version-info", shiny::htmlOutput("version_info")), |
| 135 |
shiny::sidebarLayout( |
| 136 |
# sidebar panel, defined above |
| 137 |
color_picker_sidebarPanel(), |
| 138 |
|
| 139 |
# main panel, defined above |
| 140 |
color_picker_mainPanel() |
| 141 |
) |
| 142 |
) |
| 143 |
) |
| 144 |
|
| 145 |
|
| 146 |
|