Coder Social home page Coder Social logo

rhenkin / vfinputs Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 188 KB

Visual filter inputs for Shiny apps. Interactive color legends to coordinate filtering across outputs.

License: GNU General Public License v3.0

R 62.56% CSS 0.52% JavaScript 36.92%
interactive visualization rstats shiny

vfinputs's Introduction

vfinputs

Travis build status

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

# Install from CRAN
install.packages("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.

vfinputs's People

Contributors

rhenkin avatar

Stargazers

alek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.