我是新手,我有一个问题。我想将列变量作为输入选择。我怎么不能这样做,例如我有数据不同的数据集,区tehsil参数相同但值列不同。在数据表中,当我选择输入数据集然后它显示总表,但我想在我选择某个特定区域时做出另一个输入然后它只显示该区域的tehsil和值。我附加了数据集示例pic dataset
dataset<-c(Biometric_Attendance,CFM_Parchi,Cleanliness,Consultant_Posting,Medicine_Dispensation,OverAll_Summary)library(shiny)library(rgdal)library(maptools)shinyApp(shinyUI(
fluidPage(sidebarLayout(
sidebarPanel(width = 3,selectInput("dataset","Facility Wise", choices =c("OverAll_Summary","Biometric_Attendance", "CFM_Parchi", "Cleanliness","Consultant_Posting")),selectInput("Dist",
# "District",
# c("All",
# unique(as.character(dataset$DISTRICT)))),downloadButton('downloadData', 'DownloadFacilitySummary')),mainPanel(tabsetPanel(tabPanel("Facility Wise Summary", dataTableOutput("table1"))
服务器端代码
shinyServer(function(input, output) {
datasetInput1 <- reactive({
switch(input$dataset,
"Biometric_Attendance" = Biometric_Attendance,
"CFM_Parchi" = CFM_Parchi,
"Cleanliness" = Cleanliness,
"Consultant_Posting" = Consultant_Posting ,
"OverAll_Summary"=OverAll_Summary)
}) output$table1 <- renderDataTable({
data <- dataset
if (input$Dist != "All") {
data <- data[data$DISTRICT == input$Dist,]
}
output$downloadData <- downloadHandler(
filename = function() {
paste(input$dataset, '.csv', sep='')
},
content = function(file) {
write.csv(datasetInput1(), file)
}
)
})