如何使用checkboxgroup输入在R闪亮中提出数据表?(How do I use checkboxgroup input to come up with a datatable in R shiny?)
我正在使用DT包中的数据表
尝试使用checkboxgroup输入,以便我可以为表的输出选择多个变量
我研究没有谷歌找到一些示例代码,但很难申请。
任何专家都可以帮忙!?
谢谢!!
I am using datatable from DT package trying to use checkboxgroup input so that I can select multiple variables for table's outputI have researching no google to find some example codes but it was hard to apply.
Any experts can help!?
Thank you!!
最满意答案
您可以根据复选框输入使用[]对数据进行子集化。
library(shiny) shinyApp( fluidPage( checkboxGroupInput('checkbox', 'select columns', names(mtcars), inline = TRUE), DT::dataTableOutput('table') ), function(input, output) output$table <- DT::renderDataTable({ mtcars[input$checkbox] }) )编辑 :这里有一些代码来说明我在评论中提到的内容
library(shiny) shinyApp( fluidPage( checkboxGroupInput('checkbox', 'select columns', unique(mtcars$gear), unique(mtcars$gear), inline = TRUE), DT::dataTableOutput('table') ), function(input, output) output$table <- DT::renderDataTable({ subset(mtcars, gear %in% input$checkbox) }) )You can use [] to subset your data according to the checkbox input.
library(shiny) shinyApp( fluidPage( checkboxGroupInput('checkbox', 'select columns', names(mtcars), inline = TRUE), DT::dataTableOutput('table') ), function(input, output) output$table <- DT::renderDataTable({ mtcars[input$checkbox] }) )EDIT: Here is some code to illustrate what I mentioned in the comments
library(shiny) shinyApp( fluidPage( checkboxGroupInput('checkbox', 'select columns', unique(mtcars$gear), unique(mtcars$gear), inline = TRUE), DT::dataTableOutput('table') ), function(input, output) output$table <- DT::renderDataTable({ subset(mtcars, gear %in% input$checkbox) }) )更多推荐
发布评论