I am trying to display a data table with \'n\' number of columns as shown below
Begin Date | EndDate | Month | Year | Count of Students
2/1/2014 | 1/31/2015 | Ja
Yes, using the DT
package to capture the selected rows and subset the main set. Here is an example using the iris
set:
library("dplyr")
library("shiny")
library("DT")
# create a summary table
summary_iris <- group_by(iris, Species) %>%
summarise(Count = n())
ui <- fluidPage(
dataTableOutput("summary")
, dataTableOutput("drilldown")
)
server <- function(input, output){
# display the data that is available to be drilled down
output$summary <- DT::renderDataTable(summary_iris)
# subset the records to the row that was clicked
drilldata <- reactive({
shiny::validate(
need(length(input$summary_rows_selected) > 0, "Select rows to drill down!")
)
# subset the summary table and extract the column to subset on
# if you have more than one column, consider a merge instead
# NOTE: the selected row indices will be character type so they
# must be converted to numeric or integer before subsetting
selected_species <- summary_iris[as.integer(input$summary_rows_selected), ]$Species
iris[iris$Species %in% selected_species, ]
})
# display the subsetted data
output$drilldown <- DT::renderDataTable(drilldata())
}
shinyApp(ui, server)