filterData-module: Modules for creating filters from a data.frame

Description Usage Arguments Value Note Examples

Description

Modules for creating filters from a data.frame

Usage

1
2
3
filterDataUI(id)

filterDataServer(input, output, session, data, vars = NULL, width = "100%")

Arguments

id

Module's id

input

standard shiny input.

output

standard shiny output.

session

standard shiny session.

data

a data.frame or a reactive function returning a data.frame.

vars

variables for which to create filters, by default all variables in data.

width

the width of the input, e.g. 400px, or 100%.

Value

a reactiveValues containing the data filtered under slot data, the R code to reproduce the filtering under slot code and a logical vector for indexing data under slot index.

Note

Column's names can be modified to be valid R names. Categorical columns with more than 50 unique values will be discarded.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
## Not run: 

if (interactive()) {
library(shiny)
library(shinyWidgets)
library(esquisse)

ui <- fluidPage(
  
  tags$h1("Module Filter Data"),
  
  fluidRow(
    column(
      width = 4,
      radioButtons(
        inputId = "dataset", label = "Data:",
        choices = c("iris", "mtcars", "Titanic")
      ),
      filterDataUI("ex")
    ),
    column(
      width = 8,
      progressBar(
        id = "pbar", value = 100, 
        total = 100, display_pct = TRUE
      ),
      DT::dataTableOutput(outputId = "tab"),
      verbatimTextOutput(outputId = "code")
    )
  )
  
)

server <- function(input, output, session) {
  
  data <- reactive({
    if (input$dataset == "iris") {
      return(iris)
    } else if (input$dataset == "mtcars") {
      return(mtcars)
    } else {
      return(as.data.frame(Titanic))
    }
  })
  
  res <- callModule(module = filterDataServer, 
                    id = "ex", data = data)
  
  observeEvent(res$data, {
    updateProgressBar(
      session = session, id = "pbar", 
      value = nrow(res$data), total = nrow(data())
    )
  })
  
  output$tab <- DT::renderDataTable(res$data)
  
  output$code <- renderPrint(res$code)
  
}

shinyApp(ui, server)
}


## End(Not run)

dreamRs/esquisse documentation built on July 21, 2018, 9:31 p.m.