Debian Codegraph @

inst/hclwizard/ui.R

raw
1 # -------------------------------------------------------------------
2 # - NAME: ui.R
3 # - AUTHOR: Reto Stauffer
4 # - DATE: 2015-05-01
5 # -------------------------------------------------------------------
6 # - DESCRIPTION: This is the shiny guitar tab stuff user interface.
7 # -------------------------------------------------------------------
8 # - EDITORIAL: 2015-05-01, RS: Created file on thinkreto.
9 # -------------------------------------------------------------------
10 # - L@ST MODIFIED: 2019-01-13 12:02 on marvin
11 # -------------------------------------------------------------------
12
13
14 # - Configuration
15 ticks <- FALSE # to show ticks or not to show ticks
16
17 # Note: these should be set to the config of the
18 # first (automatically loaded) palette. If not, the
19 # functionality will be the same, however, the color
20 # map will be drawn a few times whlie the script sets
21 # the new Sliders.
22 default = list("N" = 7,
23 "H1" = 340,
24 "H2" = 128,
25 "C1" = 45,
26 "CMAX" = 0,
27 "C2" = 90,
28 "L1" = 35,
29 "L2" = 95,
30 "P1" = 0.7,
31 "P2" = 1.3)
32 # Take default argument if set
33 default$N <- colorspace:::.colorspace_get_info("hclwizard_ninit")
34
35 # Hide return-to-R button on webserver
36 if ( Sys.info()["nodename"] == "sculptor.uberspace.de" ) {
37 xtra <- "$(\"#closeapp\").remove();"
38 } else { xtra <- "" }
39
40 # Define UI for application that draws a histogram
41 shinyUI(fluidPage(
42 tags$head(
43 tags$link(rel = "stylesheet", type = "text/css", href = "hclwizard.css"),
44 tags$link(rel = "stylesheet", type = "text/css", href = "hclwizard_darkmode.css"),
45 # Register palette with user-defined name: only allow
46 # alphanumeric values, spaces, underscores, and dashes.
47 HTML("<script>
48 $(document).ready(function() {
49 $(\"#registerpalettebutton\").attr(\"disabled\", \"disabled\");
50 $(\"#registerpalettename\").keyup(function(e) {
51 e.preventDefault()
52 this.value = this.value.replace(/[^A-Za-z0-9_\\s\\-]/gi, \"\");
53 if ( this.value.length == 0 ) {
54 $(\"#registerpalettebutton\").attr(\"disabled\", \"disabled\");
55 } else {
56 $(\"#registerpalettebutton\").removeAttr(\"disabled\");
57 }
58 });
59 //$(\"#registerpalettebutton\").click(function(e) {
60 // var val = $(\"#registerpalettename\").val();
61 // if ( val.length == 0 ) {
62 // ...
63 // }
64 //});\n", xtra, "\n",
65 "});
66 </script>")
67
68 ),
69 shinyjs::useShinyjs(),
70 div(class = "version-info", htmlOutput("version_info")),
71
72 # ----------------------------------------------------------------
73 # ----------------------------------------------------------------
74 sidebarPanel(
75
76 # -------------------------------------------------------------
77 # Copy the line below to make a select box
78 # -------------------------------------------------------------
79 h3("Base Options"),
80 withTags(div(class = "hcl-selectoptions", id = "hcl-typ",
81 selectInput("typ", label = h3("Type of palette"),
82 choices = list(
83 "Basic: Qualitative" = "qual",
84 "Basic: Sequential (single-hue)" = "seqs",
85 "Basic: Sequential (multi-hue)" = "seqm",
86 "Basic: Diverging" = "dive",
87 "Advanced: Sequential (single-hue)" = "seqs_advanced",
88 "Advanced: Sequential (multi-hue)" = "seqm_advanced",
89 "Advanced: Diverging" = "dive_advanced",
90 "R legacy schemes" = "base"),
91 selected = "seqm")
92 )),
93 # Copy the line below to make a select box
94 withTags(div(class = "hcl-selectoptions", id = "hcl-PAL",
95 # choices = list())
96 selectizeInput("PAL", label = h3("Base color scheme"),
97 choices = list(),
98 options = list(create = TRUE,
99 render = I('{
100 option: function(item, escape) {
101 // custom code to generate HTML before each option
102 var tmp = item.value
103 var imgname = tmp.toLowerCase().split(" ").join("_");
104 imgname = "images/pal_"+imgname+".png";
105 return( "<img class=\'select-pal\' src=\'"+imgname+"\'></img>" )
106 }
107 }')
108 )
109 )
110 )),
111 # Examples
112 withTags(div(class = "hcl-selectoptions", id = "hcl-EXAMPLE",
113 selectInput("EXAMPLE", label = h3("Example"),
114 choices = list())
115 )),
116
117
118 # -------------------------------------------------------------
119 # The checkboxes for additional options
120 # -------------------------------------------------------------
121 h3("Control Options"),
122 checkboxInput("reverse", "Reverse", value = FALSE, width = NULL),
123 checkboxInput("fixup", "Correct colors", value = TRUE, width = NULL),
124 checkboxInput("darkmode", "Dark mode", value = FALSE, width = NULL),
125 checkboxInput("desaturate", "Desaturated", value = FALSE, width = NULL),
126 radioButtons("constraint", "Vision",
127 choices = c("Normal", "Deutan", "Protan", "Tritan"),
128 selected = "Normal"),
129
130 width = 2
131 ),
132
133 # ----------------------------------------------------------------
134 # ----------------------------------------------------------------
135 sidebarPanel(
136
137 h3("Color Settings"),
138
139 # -------------------------------------------------------------
140 # - Show HUE
141 # -------------------------------------------------------------
142 htmlOutput("colorSliders"),
143 withTags(div(class = "hcl-sliderwrapper", id = "H1-wrapper",
144 withTags(span(class = "hcl-slider",
145 sliderInput("H1", label = NULL, -360, 360, default$H1, step = NULL,
146 round = TRUE, ticks = ticks, animate = FALSE,
147 width = NULL, sep = ",", pre = NULL, post = NULL)
148 )),
149 withTags(span(class = "hcl-slidervalue",
150 textInput("H1val", label = "HUE 1", width = NULL),
151 actionButton("H1set","SET")
152 )),
153 withTags(div(class = "hcl-slidervalue-compact", "H1"))
154 )),
155 withTags(div(class = "hcl-sliderwrapper", id = "H2-wrapper",
156 withTags(span(class = "hcl-slider",
157 sliderInput("H2", label = NULL, -360, 360, default$H2, step = NULL,
158 round = TRUE, ticks = ticks, animate = FALSE,
159 width = NULL, sep = ",", pre = NULL, post = NULL)
160 )),
161 withTags(span(class = "hcl-slidervalue",
162 textInput("H2val", label = "HUE 2", width = NULL),
163 actionButton("H2set", "SET")
164 )),
165 withTags(div(class = "hcl-slidervalue-compact", "H2"))
166 )),
167
168 # -------------------------------------------------------------
169 # - Show CHOMA
170 # -------------------------------------------------------------
171 withTags(div(class = "hcl-sliderwrapper", id = "C1-wrapper",
172 withTags(span(class = "hcl-slider",
173 sliderInput("C1", label=NULL, 0, 100, default$C1, step = NULL,
174 round = TRUE, ticks = FALSE, animate = FALSE,
175 width = NULL, sep = ",", pre = NULL, post = NULL)
176 )),
177 withTags(span(class = "hcl-slidervalue",
178 textInput("C1val", label="CHROMA 1", width = NULL),
179 actionButton("C1set","SET")
180 )),
181 withTags(div(class = "hcl-slidervalue-compact", "C1"))
182 )),
183 withTags(div(class = "hcl-sliderwrapper", id = "CMAX-wrapper",
184 withTags(span(class = "hcl-slider",
185 sliderInput("CMAX", label=NULL, 0, 100, default$CMAX, step = NULL,
186 round = TRUE, ticks = FALSE, animate = FALSE,
187 width = NULL, sep = ",", pre = NULL, post = NULL)
188 )),
189 withTags(span(class = "hcl-slidervalue",
190 textInput("CMAXval", label="MAX CHROMA", width = NULL),
191 actionButton("CMAXset","SET")
192 )),
193 withTags(div(class = "hcl-slidervalue-compact", "CX"))
194 )),
195 withTags(div(class = "hcl-sliderwrapper", id = "C2-wrapper",
196 withTags(span(class = "hcl-slider",
197 sliderInput("C2", label=NULL, 0, 100, default$C2, step = NULL,
198 round = TRUE, ticks = FALSE, animate = FALSE,
199 width = NULL, sep = ",", pre = NULL, post = NULL)
200 )),
201 withTags(span(class = "hcl-slidervalue",
202 textInput("C2val", label="CHROMA 2", width = NULL),
203 actionButton("C2set","SET")
204 )),
205 withTags(div(class = "hcl-slidervalue-compact", "C2"))
206 )),
207
208 # -------------------------------------------------------------
209 # - Show LUMINANCE
210 # -------------------------------------------------------------
211 withTags(div(class = "hcl-sliderwrapper", id = "L1-wrapper",
212 withTags(span(class = "hcl-slider",
213 sliderInput("L1", label = NULL, 0, 100, default$L1, step = NULL,
214 round = TRUE, ticks = FALSE, animate = FALSE,
215 width = NULL, sep = ",", pre = NULL, post = NULL)
216 )),
217 withTags(span(class = "hcl-slidervalue",
218 textInput("L1val", label = "LUMIN. 1", width = NULL),
219 actionButton("L1set","SET")
220 )),
221 withTags(div(class = "hcl-slidervalue-compact", "L1"))
222 )),
223 withTags(div(class = "hcl-sliderwrapper", id = "L2-wrapper",
224 withTags(span(class = "hcl-slider",
225 sliderInput("L2", label = NULL, 0, 100, default$L2, step = NULL,
226 round = TRUE, ticks = FALSE, animate = FALSE,
227 width = NULL, sep = ",", pre = NULL, post = NULL)
228 )),
229 withTags(span(class = "hcl-slidervalue",
230 textInput("L2val", label = "LUMIN. 2", width = NULL),
231 actionButton("L2set","SET")
232 )),
233 withTags(div(class = "hcl-slidervalue-compact", "L2"))
234 )),
235
236 # -------------------------------------------------------------
237 # - Show POWER
238 # -------------------------------------------------------------
239 withTags(div(class = "hcl-sliderwrapper", id = "P1-wrapper",
240 withTags(span(class = "hcl-slider",
241 sliderInput("P1", label = NULL, 0, 3, default$P1, step = 0.05,
242 round = FALSE, ticks = FALSE, animate = FALSE,
243 width = NULL, sep = ",", pre = NULL, post = NULL)
244 )),
245 withTags(span(class = "hcl-slidervalue",
246 textInput("P1val", label = "POWER 1", width = NULL),
247 actionButton("P1set","SET")
248 )),
249 withTags(div(class = "hcl-slidervalue-compact", "P1"))
250 )),
251 withTags(div(class = "hcl-sliderwrapper", id = "P2-wrapper",
252 withTags(span(class = "hcl-slider",
253 sliderInput("P2", label = NULL, 0, 3, default$P2, step = 0.05,
254 round = FALSE, ticks = FALSE, animate = FALSE,
255 width = NULL, sep = ",", pre = NULL, post = NULL)
256 )),
257 withTags(span(class = "hcl-slidervalue",
258 textInput("P2val", label="POWER 2", width = NULL),
259 actionButton("P2set","SET")
260 )),
261 withTags(div(class = "hcl-slidervalue-compact", "P2"))
262 )),
263
264 # -------------------------------------------------------------
265 # - Show NUMBER OF COLORS
266 # -------------------------------------------------------------
267 withTags(div(class = "hcl-sliderwrapper", id = "N-wrapper",
268 withTags(span(class = "hcl-slider",
269 sliderInput("N", label=NULL, 2, 40, default$N, step = NULL,
270 round = TRUE, ticks = FALSE, animate = FALSE,
271 width = NULL, sep = ",", pre = NULL, post = NULL)
272 )),
273 withTags(span(class = "hcl-slidervalue",
274 textInput("Nval", label="NUMBER", width = NULL),
275 actionButton("Nset", "SET")
276 )),
277 withTags(div(class = "hcl-slidervalue-compact", "N"))
278 )),
279
280
281 # -------------------------------------------------------------
282 # Color map plot
283 # -------------------------------------------------------------
284 # The color map
285 plotOutput("colormap", height = "40px", width = "100%"),
286
287 actionButton("closeapp", "Return to R"),
288
289 width = 3
290 ),
291 mainPanel(
292
293 # -------------------------------------------------------------
294 # Main panel which shows the plot.
295 # -------------------------------------------------------------
296 tabsetPanel(id = "maintabs",
297 tabPanel("Example Plot", value = "plotexample",
298 withTags(div(class = "hcl-main", id = "hcl-main-plot",
299 plotOutput("plot")
300 ))
301 ),
302 # -------------------------------------------------------------
303 # Show color spectrum
304 # -------------------------------------------------------------
305 tabPanel("Spectrum", value = "spectrum",
306 withTags(div(class = "hcl-main", id = "hcl-main-spectrum",
307 plotOutput("spectrum")
308 ))
309 ),
310 # -------------------------------------------------------------
311 # Color pane plot
312 # -------------------------------------------------------------
313 tabPanel("Color Plane", value = "colorplane",
314 includeHTML("html/colorplane.html"),
315 withTags(div(class = "hcl-main", id = "hcl-main-colorplane",
316 plotOutput("colorplane")
317 ))
318 ),
319 # -------------------------------------------------------------
320 # Export panel
321 # -------------------------------------------------------------
322 tabPanel("Export", value = "export", icon = icon("download", lib = "font-awesome"),
323 withTags(div(class = "hcl-main", id = "hcl-main-export",
324 tabsetPanel(
325 # RAW output (rgb,RGB,hex)
326 tabPanel("RAW",
327 withTags(div(class = "output-raw",
328 htmlOutput("exportRAW1"),
329 downloadButton("downloadRAW1", "Download")
330 )),
331 withTags(div(class = "output-raw",
332 htmlOutput("exportRAW2"),
333 downloadButton("downloadRAW2", "Download")
334 )),
335 withTags(div(class = "output-raw",
336 htmlOutput("exportRAW3"),
337 downloadButton("downloadRAW3", "Download")
338 )),
339 withTags(div(class = "output-raw",
340 htmlOutput("exportRAW4")
341 ))
342 ),
343 # GrADS style output
344 tabPanel("GrADS",
345 htmlOutput("exportGrADS"),
346 includeHTML("html/GrADS.html")
347 ),
348 # Python output
349 tabPanel("Python",
350 includeHTML("html/python.html"),
351 htmlOutput("exportPython")
352 ),
353 # Matlab output
354 tabPanel("MATLAB",
355 htmlOutput("exportMatlab"),
356 includeHTML("html/matlab.html")
357 ),
358 # Matlab output
359 tabPanel("R",
360 includeHTML("html/R.html"),
361 htmlOutput("exportFun"),
362 includeHTML("html/RReg.html"),
363 htmlOutput("exportFunReg2")
364 ),
365 # Register palette
366 if ( ! Sys.info()["nodename"] == "sculptor.uberspace.de" ) {
367 tabPanel("Register",
368 includeHTML("html/Register.html"),
369 withTags(span(class = "registerpalette",
370 textInput("registerpalettename", label = NULL, width = "200px"),
371 actionButton("registerpalettebutton","Register")
372 )),
373 includeHTML("html/RegisterRcode.html"),
374 htmlOutput("exportFunReg")
375 )
376 }
377 )
378 ))
379 ),
380 # -------------------------------------------------------------
381 # Main panel which shows the help pages. Hidden in the beginning,
382 # displayed on request.
383 # -------------------------------------------------------------
384 tabPanel("Info", value = "info", icon = icon("info-circle", lib = "font-awesome"),
385 withTags(div(class = "hcl-main", id = "hcl-main-help",
386 includeHTML("html/info.html")
387 ))
388 )
389 ),
390
391
392 width = 7
393
394 )
395 ))