Skip to contents

Allow to take a sample of data.frame for a given number or proportion of rows to keep.

Usage

sample_ui(id)

sample_server(id, data_r = reactive(NULL))

Arguments

id

Module id. See shiny::moduleServer().

data_r

reactive containing a data.frame to use in the module.

Value

  • UI: HTML tags that can be included in shiny's UI

  • Server: a reactive fgunction with the sampled data.

Examples

library(shiny)
library(datamods)
library(reactable)


ui <- fluidPage(

  tags$h2("Sampling"),

  fluidRow(
    column(
      width = 3,
      sample_ui("myID")
    ),
    column(
      width = 9,
      reactableOutput("table")
    )
  )
)


server <- function(input, output, session) {

  result_sample <- sample_server("myID", reactive(iris))

  output$table <- renderReactable({
    table_sample <- reactable(
      data = result_sample(),
      defaultColDef = colDef(
        align = "center"
      ),
      borderless = TRUE,
      highlight = TRUE,
      striped = TRUE
    )
    return(table_sample)
  })
}

if (interactive())
  shinyApp(ui, server)