我正在尝试在选中复选框时打印表格。这工作正常,但我不想打印所有列,即只有“名称”和“颜色”。
不幸的是,我找不到显示特定列的命令。我认为input$color
可以解决问题,但我无法正确运行脚本。
这是我的最小例子:
mydat <- data.table( id=c(1,2,3,4),
londd=c(20, 38, 96, 32),
latdd=c(60, 56, 30, 31),
material=c("stone", "water,sand", "sand", "wood"),
application=c("a","b","c","d"),
name=c("1","2","3","4"),
color=c("red","green","blue","yellow"))
#Set up ui
ui <- shinyUI(fluidPage(
sidebarPanel(h5("", width=2),
checkboxGroupInput(inputId="MatFlag",label=h4("Material"),
choices=setNames(object=c("stone","water","sand", "wood"),
nm=c("stone", "water", "sand", "wood"))
),
checkboxGroupInput(inputId="AppFlag",label=h4("Application"),
choices=setNames(object=c("a","b","c","d"),
nm=c("a","b","c","d"))
),
position="left"),
#App mainPanel content and styles
mainPanel("Plot_and_table","Plot and Table",
"button_plot_and_table",size="large",dataTableOutput("TestTable"))))
#Set up server
server <- function(input, output){
#Filter data
datFilt <- reactive({
MatSearch <- paste0(c('xxx',input$MatFlag),collapse = "|")
MatSearch <- gsub(",","|",MatSearch)
mydat[grepl(MatSearch,material) & application %in% input$AppFlag]
})
output$TestTable <- renderDataTable({datFilt()
}, options = list(pageLength=5))
}
#Run app
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
如果只是你想要的子集,这应该没问题:
datFilt <- reactive({
MatSearch <- paste0(c('xxx',input$MatFlag),collapse = "|")
MatSearch <- gsub(",","|",MatSearch)
testdata <- mydat[grepl(MatSearch,material) & application %in% input$AppFlag]
testdata[,c("name","color"), with=FALSE]
})