I'm using Data Table library in Shiny to create a Table Container.
I want to drop columns using checkboxGroupInput or any input but currently its not working.
Can someone please guide me? I shall be extremely grateful.
Same question is posted on stackoverflow as follows, you can cross check answers:
Regards
My Codes:
library(shiny)
library(DT)
iris<-iris[,c(5,1:4)]
ui =basicPage(
selectInput(inputId = "Species",
label = "Species:",
choices = c("All",
unique(as.character(iris$Species)))),
checkboxGroupInput(inputId = "columns", label = "Select Variable:",
choices =names(iris),selected = names(iris)),
h2('Iris Table'),
DT::dataTableOutput('mytable')
)
server = function(input, output) {
output$mytable = DT::renderDataTable({
# a custom table container
sketch = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, 'Species'),
th(colspan = 2, 'Sepal'),
th(colspan = 2, 'Petal')
),
tr(
lapply(rep(c('Length', 'Width'), 2), th)
)
)
))
DT::datatable(filter = "top", rownames = FALSE, container = sketch,
extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons =
c('copy', 'csv', 'excel', 'pdf', 'print')
),
{
data<-iris
if(input$Species != 'All'){
data<-data[data$Species == input$Species,]
}
data<-data[,c(input$columns),drop=FALSE]
data
})}) }
shinyApp(ui = ui, server = server)