filterData: shiny UI to filter data

Description Usage Arguments Examples

Description

A module to enable data filtering in shiny applications. The ui function is populated with column filters that can be manipulated by the user. The server function is returning the R expression corresponding to filters defined by user and eventually the filtered dataset.

Usage

1
2
3
4
5
filterDataUI(id)

filterDataServer(input, output, session, x = reactive(NULL),
  domain = list(), default_show = TRUE, show_all_filters = TRUE,
  return_data = FALSE)

Arguments

id

namespace identifier for the module

input, output, session

mandatory arguments for modules to be valid. These should not to be defined as they will be handled by shiny.

x

the input data.frame to be filtered. It must be a reactive value.

domain

a list containing domain data for one or more columns. It must be a list with components min and max if numeric, first and last date if Date, list of levels or character values if character or factor.

default_show

should the filters be expanded when UI is is shown first. If FALSE, the UIs showing filters are hidden.

show_all_filters

if TRUE, all filters UI are shown. If FALSE, a compact UI is displayed containing a select box to choose a variable filter and a dynamic filter corresponding to the filter to display.

return_data

whether the filtered dataset should be also returned in the reactive value returned by the module.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
library(shinytools)
library(shiny)

# example with dataTableOutput and renderDataTable ----
if (interactive()) {
  options(device.ask.default = FALSE)

  ui <- fluidPage(
    fluidRow(
      column(
        width = 4,
        filterDataUI(id = "demo")
      ),
      column(width = 8, dataTableOutput(outputId = "subsetdata"))
    )
  )

  server <- function(input, output, session) {
    res <- callModule(module = filterDataServer,
                      id = "demo", x = reactive(iris),
                      return_data = TRUE)

    observe({
      req(res)
      print(res$expr)
    })

    output$subsetdata <- renderDataTable({
      res$filtered_data
    })
  }
  print(shinyApp(ui, server))
}

ardata-fr/shinytools documentation built on Nov. 15, 2019, 7:53 p.m.