项目作者: davesteps

项目描述 :
Cascading filter modules for Shiny
高级语言: R
项目地址: git://github.com/davesteps/shinyFilters.git
创建时间: 2016-10-21T22:15:34Z
项目社区:https://github.com/davesteps/shinyFilters

开源协议:Apache License 2.0

下载


shinyFilters

The idea of shinyFilters is to allow quick and easy filtering of data.frames in Shiny.

  • The filter choices are cascading - If the user chooses ‘USA’ and ‘Asia’ in filter 1. All subsequent filters will be updated to only contain choices which meet this criteria.

  • Enable/disable child filter based on condition of parent - Filter 2 is only enabled when ‘USA’ or ‘Asia’ are selected in filter 1.

Installation

Install using the devtools package

  1. # Install devtools, if you haven't already.
  2. install.packages("devtools")
  3. devtools::install_github("davesteps/shinyFilters")

Usage

Example 1 (see here)

  1. library(shiny)
  2. library(shinyjs)
  3. library(dplyr)
  4. library(shinyFilters)
  5. # create filterset in global section of app
  6. filterSet <- newFilterSet('FS1') %>%
  7. # give each filter unique id and tell it which column to filter on
  8. addSelectFilter('cylinders','cyl') %>%
  9. addSelectFilter('gears','gear') %>%
  10. addSliderFilter('disp',value=c(0,500)) %>%
  11. addSelectFilter('carb') %>%
  12. addCustomSliderFilter('hp',value=seq(0,500,50))
  13. ui <- fluidPage(
  14. #shinyjs is required to show/hide filters
  15. useShinyjs(),
  16. sidebarLayout(
  17. sidebarPanel(
  18. filterInputs(filterSet),
  19. hr(),
  20. filterMaster(filterSet),
  21. filterResetButton(filterSet)
  22. ),
  23. mainPanel(
  24. DT::dataTableOutput("data")
  25. )
  26. )
  27. )
  28. server <- function(input, output,session) {
  29. # wrap data in reactive expression in case you
  30. # need to do something to the data before filtering
  31. data <- reactive(mtcars)
  32. # initialize the filter set
  33. filterSet <- initializeFilterSet(filterSet, data)
  34. # the output is a reactive data.frame
  35. output$data <- DT::renderDataTable(filterSet$output())
  36. }
  37. shinyApp(ui, server)