module-sample {datamods}R Documentation

Shiny module to interactively sample a data.frame

Description

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

Examples

library(shiny)
library(reactable)

##### ui.R #####

ui <- fluidPage(

  titlePanel("Sampling"),

  fluidRow(
    column(
      width = 4,
      sample_ui("myID")
    ),
    column(
      width = 8,
      reactableOutput("table")
    )
  )
)



##### server.R #####

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)


[Package datamods version 1.5.0 Index]