Hope you all are well. I'm facing a small problem with ShinyApps. I have attached a picture of what i require. I'm basically targeting cyl variable of mtcars data. If i press 4 from it, i require the filtered data having 4 along-with rest of variables having four attached to their names. Likewise if i press 4 and 6 together, i require filtered data having 4 and 6 of cyl along with four and six attached to rest of variable names. The attached picture will make things easier to understand. I'm attaching my codes as well. Please guide me. Bundle of thanks in advance :)
data_table<-mtcars
library(shiny)
ui <- fluidPage(
checkboxGroupInput(inputId = "variables", label = "Choose number(s):",
choices =c("4","6", "8"),
selected = c("4")),
DT::dataTableOutput("distable"))
server <- function(input, output){
thedata <- reactive({
if(input$variables != '0'){
data_table<-data_table[data_table$cyl %in% input$variables,]
}
#
# if(input$variables == '4'){
# names(data_table)[3:11]<-paste( "four","_" ,names(data_table)[3:11])
# }
#
# if(input$variables == '6'){
# names(data_table)[3:11]<-paste( "six","_" ,names(data_table)[3:11])
# }
#
# if(input$variables == '8'){
# names(data_table)[3:11]<-paste( "eight","_" ,names(data_table)[3:11])
# }
#
#
})
output$distable = DT::renderDataTable({
DT::datatable( filter = "top",
{ thedata() # Call reactive thedata()
})
})
}
shinyApp(ui = ui, server = server)