esquisse (version 0.1.2.900)

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

Description

Modules for creating filters from a data.frame

Usage

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.

Examples

Run this code
# NOT RUN {
# }
# 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)
}

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab