【发布时间】:2019-05-24 12:47:12
【问题描述】:
希望你们一切都好。我在使用 ShinyApps 时遇到了一个小问题。 我附上了我需要的图片。 我基本上针对 mtcars 数据的 cyl 变量。如果我从中按 4,我需要过滤后的数据具有 4 以及其余变量的名称附有 4。 同样,如果我同时按下 4 和 6,我需要过滤后的数据具有 cyl 的 4 和 6 以及附加到其余变量的 4 和 6名字。 附图将使事情更容易理解。 我也附上我的代码。 请指导我。提前致谢:)
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)
【问题讨论】:
-
对于 4 和 6 部分,如果 4 和 6 有不同的行怎么办?如图所示,输出不能是
cbind表 -
嗨伙计,现在我们可以假设行数相同,我们也可以做 cbind。如果可能的话,您能否更新代码。非常感谢
标签: r datatable shiny radio-button dashboard