MyNixOS website logo
Description

Visual Filter Inputs for Shiny.

A set of visual input controls for Shiny apps to facilitate filtering across multiple outputs.

vfinputs

Travis buildstatus

vfinputs provides visual filter inputs for Shiny apps. The current version includes color legends that enable users of Shiny apps to interactively set numeric and categorical filters. Shiny programmers can use the values returned by the inputs to coordinate filtering across multiple outputs, using a unified color legend rather than those rendered by a plotting package.

Installation

You can install vfinputs with:

remotes::install_github("rhenkin/vfinputs")

Usage

The inputs should be used as any other Shiny input, added in the UI (or created using renderUI) and accessed in the server function. At the moment, there are two numeric legends (continuous and discrete) and one categorical one. The numeric legends include a brush interaction to select a range of values. The categorical legend includes a click-to-toggle interaction, with single or multiple selections being possible.

library(vfinputs)

ui <- fluidPage(
  
   # Using minValue, maxValue and colors
   continuousColorFilter("filter", minValue = 0, maxValue = 200, colors = c("#ad2a2a", "#3f91e8")),
   
   # Using data and colors
   continuousColorFilter("filter2", data = mtcars$mpg, colors = c("#ad2a2a", "#3f91e8")),
   
   # Using data and palette
   continuousColorFilter("filter3", data = mtcars$mpg, palette = scales::viridis_pal())
  
   # Defining the number of colors through n for a discrete selection
   discreteColorFilter("filter4", minValue = 0, maxValue = 200, colors = c("#ad2a2a", "#3f91e8"), n = 5),
   
   # Categorical legend
   categoricalColorFilter("filter5", values = c("Yes", "No"), colors = c("#FF0000", "#FF00FF"))
   
   # Single selection
   categoricalColorFilter("filter5", values = c("Yes", "No"), colors = c("#FF0000", "#FF00FF"), multiple = FALSE)
 )

The numeric legends return start and end values of the brushed interval. The categorical legend returns a list with the selected values.

server <- function(input, output) {
   output$value <- output$selection <- renderPrint({
   if (!is.null(input$filter)) {
     paste0(input$filter$start, ",", input$filter$end)
     }
   })
 }

For detailed examples of how to use the different arguments see the visualtests folder in this repository.

Customizing and extending

Ticks and labels

Under the hood, the axes and brushes are implemented using D3.js. The options argument for the numeric scales can contain custom "format" for the labels and "ticks" for deciding which/how many ticks to show. For the supported format strings, please see https://github.com/d3/d3-format#locale_format. Ticks can be a number or a list with custom tick values to display.

CSS

The style of the legends, including axis and brush, can easily customized with CSS, just like any other Shiny input. The key classes to look for are "div.continuous-color-filter", "div.discrete-color-filter" and "div.categorical-color-filter". Additional elements can be found and customized using the browser inspecting tool.

Custom axis and interaction

The key purpose of the UI functions is to connect the rendering of the color legend with the D3-powered interaction. Thus, the package also exports the base functions that creates the color legends , numericLegend() and categoricalLegend(), and which can be combined with custom JavaScript code to re-implement the axes and brushes.

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows