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
div( | |
shiny::textInput(inputId = "custom"), | |
HMTL("<script> | |
$('#custom').spectrum({ | |
color: '#f00' | |
}); | |
</script>" | |
) | |
) |
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
library(shiny) | |
library(glue) | |
source("DoubleColorPickerInput.R") | |
ui <- fluidPage( | |
tags$head( | |
tags$link(rel = "stylesheet", type = "text/css", href = "spectrum.css"), | |
tags$script(src="spectrum.js") |
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
// DoubleColorPicker Input Binding | |
// | |
// Definition of a Shiny InputBinding extension to | |
// get the values of two color pickers. | |
// | |
// https://github.com/zappingseb/customshinyinput | |
// Author: Sebastian Wolf | |
// License: MIT | |
// ----------------------------------------------------- |
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
getValue: function(el) { | |
// create an empty output array | |
var output = [] | |
// go over each input element inside the | |
// defined InputBinding and add the ID | |
// and the value as a dictionary to the output | |
$(el).find("input").each(function(inputitem){ | |
output.push({ |
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
// DoubleColorPicker Input Binding | |
// | |
// Definition of a Shiny InputBinding extension to | |
// get the values of two color pickers. | |
// | |
// https://github.com/zappingseb/customshinyinput | |
// Author: Sebastian Wolf | |
// License: MIT | |
// ----------------------------------------------------- |
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
subscribe: function(el, callback) { | |
// the jQuery "change" function allows you | |
// to notice any change to your input elements | |
$(el).on('change.input', function(event) { | |
callback(false); | |
// When called with false, it will NOT use the rate policy, | |
// so changes will be sent immediately | |
}); | |
} |
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
#' Function to return a DoubleColorPicker input | |
#' @param id (\code{character}) A web element ID, shall not contain dashes or underscores or colon | |
#' @param col_border (\code{character}) A hex code for the border color default value | |
#' @param col_fill (\code{character}) A hex code for the fill color default value | |
#' @return An \code{shiny::div} element with two color pickers | |
#' @author Sebastian Wolf \email{sebastian@@mail-wolf.de} | |
DoubleColorPickerInput <- function(id="fancycolorpicker", col_border = "#f00", col_fill="#00f"){ | |
# Return a div element of class "doubleclorpicker" | |
div( |
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
// DoubleColorPicker Input Binding | |
// | |
// Definition of a Shiny InputBinding extension to | |
// get the values of two color pickers. | |
// | |
// https://github.com/zappingseb/customshinyinput | |
// Author: Sebastian Wolf | |
// License: MIT | |
// ----------------------------------------------------- |
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
# Try to remove the input Handler as shiny does not allow double input | |
# handlers | |
try({ removeInputHandler("DoubleColorPickerBinding") }) | |
# Use the shiny registerInputHandler function to | |
# register a way to deal with the inputs coming | |
shiny::registerInputHandler( | |
"DoubleColorPickerBinding", | |
function(x, shinysession, name) { | |
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
HTML(glue("<script>$('#{id}').on('change',function(){{check_doublecolorpicker('{id}');}});</script>")), | |
HTML("<div class='warning' style='color:red;display:none'>Please choose more different colors</div>") |
OlderNewer