Title: | Visual Filter Inputs for Shiny |
---|---|
Description: | A set of visual input controls for Shiny apps to facilitate filtering across multiple outputs. |
Authors: | Rafael Henkin [cre, aut] |
Maintainer: | Rafael Henkin <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2025-02-11 03:11:30 UTC |
Source: | https://github.com/rhenkin/vfinputs |
Add list of category items
addCategoryBlocks(orient, input_id, color_map, values)
addCategoryBlocks(orient, input_id, color_map, values)
orient |
Orientation of the legend. Can be |
input_id |
The CSS class used to trigger interactions |
color_map |
A list of colors from where the corresponding item color will be retrieved |
values |
A list of values from which the corresponding item label will be retrieved |
A list of the same length as values, containing either "span"
or "div"
elements depending on the chosen orientation.
Add list of colored strips
addColorStrips(n_strips, color_map, orient, pos_function, size, thickness = 20)
addColorStrips(n_strips, color_map, orient, pos_function, size, thickness = 20)
n_strips |
Number of strips to be added |
color_map |
A list of colors corresponding to the number of strips |
orient |
Orientation of the legend. Can be |
pos_function |
A function to convert from index number to pixels |
size |
The length of the list in pixels |
thickness |
The height or width of the list in pixels |
A list of SVG rect
shapes.
Add a visual filter input for categorical data
categoricalColorFilter(inputId, ...)
categoricalColorFilter(inputId, ...)
inputId |
The |
... |
Arguments passed on to
|
A visual filter input control that can be added to a UI definition
start
and end
bounds of a selection. The default value (or empty selection) is NULL
.
Other visual filters:
continuousColorFilter()
,
discreteColorFilter()
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( categoricalColorFilter("filter", data = sort(mtcars$gear), orient = "right", palette = RColorBrewer::brewer.pal(8, "Dark2")), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { format(input$filter) } }) } shinyApp(ui, server) ui <- fluidPage( categoricalColorFilter("filter", label = p("Categorical filter:"), palette = RColorBrewer::brewer.pal(3, "Accent"), values = list("a","b","c")), verbatimTextOutput("values") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { format(input$filter) } }) } shinyApp(ui, server) }
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( categoricalColorFilter("filter", data = sort(mtcars$gear), orient = "right", palette = RColorBrewer::brewer.pal(8, "Dark2")), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { format(input$filter) } }) } shinyApp(ui, server) ui <- fluidPage( categoricalColorFilter("filter", label = p("Categorical filter:"), palette = RColorBrewer::brewer.pal(3, "Accent"), values = list("a","b","c")), verbatimTextOutput("values") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { format(input$filter) } }) } shinyApp(ui, server) }
Create a color legend based on given data and palette or colors. Also passes on data- attributes for optional JS interaction.
categoricalLegend( inputId, label = NULL, class = "", values = NULL, data = NULL, colors = NULL, palette = NULL, orient = "bottom", size = 220, multiple = TRUE )
categoricalLegend( inputId, label = NULL, class = "", values = NULL, data = NULL, colors = NULL, palette = NULL, orient = "bottom", size = 220, multiple = TRUE )
inputId |
The |
label |
Display label for the control, or |
class |
The CSS class of the input div element to match with any filter toggling functions. Default class is |
values |
List of character vectors that will match with the colors or palette in the order provided by both. |
data |
Alternative vector to extract values with |
colors |
Colours to match with values; must be a valid argument to
|
palette |
A function that outputs a list of colors. |
orient |
Orientation of the legend. Can be |
size |
Absolute length in pixels of the color bar; becomes width or height depending on value of |
multiple |
Is selection of multiple items allowed? Default is |
A categorical color legend control that can be added to a UI definition
discreteColorFilter()
continuousColorFilter()
categoricalColorFilter()
Other base legend:
numericLegend()
Add a color-label block
categoryBlock(i, values, tag_name, class, color_map)
categoryBlock(i, values, tag_name, class, color_map)
i |
The index of the item to be created |
values |
A list of values from which the corresponding item label will be retrieved |
tag_name |
An HTML element tag |
class |
The HTML element class that will enable interaction |
color_map |
A list of colors from where the corresponding item color will be retrieved |
An HTML element with pointer cursor, a colored square and a label
Add color strip
colorStrip(color, x = 0, y = 0, width = 1, height = 30)
colorStrip(color, x = 0, y = 0, width = 1, height = 30)
color |
A valid CSS color name |
x |
The x position of the |
y |
The y position of the |
width |
The width of the |
height |
The height of the |
A rect
element with the color
argument as fill and stroke
The brush used in this filter allows a free selection over the whole input range.
continuousColorFilter(inputId, ...)
continuousColorFilter(inputId, ...)
inputId |
The |
... |
Arguments passed on to
|
A visual filter input control that can be added to a UI definition.
start
and end
bounds of a selection. The input value is NULL
for empty selections.
discreteColorFilter()
categoricalColorFilter()
Other visual filters:
categoricalColorFilter()
,
discreteColorFilter()
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( continuousColorFilter("filter", minValue = 0, maxValue = 200, palette = scales::viridis_pal()), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { paste0(input$filter$start, ",", input$filter$end) } }) } shinyApp(ui, server) ui <- fluidPage( continuousColorFilter("filter", data = mtcars$mpg, colors = c("#FF0000", "#0000FF")), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { paste0(input$filter$start, ",", input$filter$end) } }) } shinyApp(ui, server) }
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( continuousColorFilter("filter", minValue = 0, maxValue = 200, palette = scales::viridis_pal()), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { paste0(input$filter$start, ",", input$filter$end) } }) } shinyApp(ui, server) ui <- fluidPage( continuousColorFilter("filter", data = mtcars$mpg, colors = c("#FF0000", "#0000FF")), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { paste0(input$filter$start, ",", input$filter$end) } }) } shinyApp(ui, server) }
The brush used in this filter snaps to evenly divided steps based on the number of colors passed as argument. With minValue = 0, maxValue = 100 and n = 5, it will snap at the edges (0 and 100) and 20, 40, 60, and 80.
discreteColorFilter(inputId, ...)
discreteColorFilter(inputId, ...)
inputId |
The |
... |
Arguments passed on to
|
A visual filter input control that can be added to a UI definition.
start
and end
bounds of a selection. The input value is NULL
for empty selections.
start
and end
bounds of a selection. The default value is null.
Other visual filters:
categoricalColorFilter()
,
continuousColorFilter()
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( discreteColorFilter("filter", minValue = 0, maxValue = 200, n = 5, palette = scales::viridis_pal()), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { paste0(input$filter$start, ",", input$filter$end) } }) } shinyApp(ui, server) }
## Only run examples in interactive R sessions if (interactive()) { ui <- fluidPage( discreteColorFilter("filter", minValue = 0, maxValue = 200, n = 5, palette = scales::viridis_pal()), verbatimTextOutput("value") ) server <- function(input, output) { output$value <- output$selection <- renderPrint({ if (!is.null(input$filter)) { paste0(input$filter$start, ",", input$filter$end) } }) } shinyApp(ui, server) }
Create a color legend based on given data and palette or colors. Also passes on data- attributes for optional JS interaction.
numericLegend( inputId, label = NULL, class = "", n = 100, minValue = NULL, maxValue = NULL, data = NULL, colors = NULL, palette = NULL, options = NULL, orient = "bottom", size = 200, thickness = 20, offset = 0 )
numericLegend( inputId, label = NULL, class = "", n = 100, minValue = NULL, maxValue = NULL, data = NULL, colors = NULL, palette = NULL, options = NULL, orient = "bottom", size = 200, thickness = 20, offset = 0 )
inputId |
The |
label |
Display label for the control, or |
class |
The CSS class of the input div element to match with any brush-defining functions. Default classes for brushes are either |
n |
Number of color strips in the legend. Default is |
minValue |
Minimum numeric value in the legend (can be higher the maximum for inverted scale). |
maxValue |
Maximum numeric value in the legend (can be lower the minimum for inverted scale). |
data |
Alternative vector to extract numeric minimum and maximum values. |
colors |
Colours to interpolate; must be a valid argument to
|
palette |
A function that outputs a list of colors |
options |
Configuration options for brush and scale. Use |
orient |
Orientation of the legend. Can be |
size |
Absolute length in pixels of the color bar; becomes width or height depending on value of |
thickness |
Absolute thickness in pixels of the color bar; opposite of size depending on value of |
offset |
Left offset for scale to allow long labels. Default is |
A numeric color legend control that can be added to a UI definition
discreteColorFilter()
continuousColorFilter()
categoricalColorFilter()
Other base legend:
categoricalLegend()
Change a categorical legend in the client
updateCategoricalFilter( session, inputId, label = NULL, select = NULL, deselect = NULL )
updateCategoricalFilter( session, inputId, label = NULL, select = NULL, deselect = NULL )
session |
The |
inputId |
The id of the input object. |
label |
The label to set for the input object. |
select |
Items to be selected. |
deselect |
Items to be deselected. |
This function only affects the label and the selection. Re-creating the items requires deleting and re-creating the legend using shinyjs
, for example.
Other update functions:
updateNumericFilter()
This function does not validate if a brush is already defined; updating only one of start or end with an empty brush will assign the other to NaN.
updateNumericFilter( session, inputId, label = NULL, start = NULL, end = NULL, minValue = NULL, maxValue = NULL )
updateNumericFilter( session, inputId, label = NULL, start = NULL, end = NULL, minValue = NULL, maxValue = NULL )
session |
The |
inputId |
The id of the input object. |
label |
The label to set for the input object. |
start |
Beginning of selection interval. |
end |
End of selection interval. |
minValue |
Minimum numeric value in the legend (can be higher the maximum for inverted scale). |
maxValue |
Maximum numeric value in the legend (can be lower the minimum for inverted scale). |
This function only affects the label and JavaScript-implemented axis and brush values and selection.
Re-creating the color strips and changing the ticks and format of values requires deleting and re-creating the legend using shinyjs
, for example.
continuousColorFilter()
discreteColorFilter()
Other update functions:
updateCategoricalFilter()