r语言 - 如何下载一个csv文件的RShiny使用checkBoxGroup检查列表



我是闪亮的应用程序,我需要帮助我的代码。我已经为一组项目(choicnames)创建了一个复选框列表,并且我希望用户能够仅以csv文件的形式下载选中项目(choiceValues)的值。在这种情况下,我如何编写输出代码?在ShinyApp

检查列表的图片
ui <- fluidPage(
titlePanel(h1(" Birth Worksheet",align="center")),
hr(),
sidebarPanel(  
titlePanel(h4("Antenatal Risk Factors/Current Pregnancy",align="center")),
hr(),
checkboxGroupInput("Antel", "  ",
choiceNames =
list("Urinary tract infections this pregnancy",
"Urinary tract infections this pregnancy, treated",
"Anemia this pregnancy (HCT < 30/Hgb <10)",
"Hemoglobinopathy this pregnancy",
"Coagulation disorder",
"Rh sensitization",
"Other iso-immunization",
"Biliary/liver disorder(Yes at delivery)",
"Cardiac disease",
"Autoimmune disease",
"Antiphospholipid syndrome",
"Specify collagen vascular disease",
"Asthma",
"Acute or chronic lung disease",
"Renal disorder/disease",
"Renal dialysis or end stage renal disease",
"Thyroid disease",
"Cancer this pregnancy",
"Cancer treatment this pregnancy"
),
choiceValues =list("RFC_INFUT","RFC_INFUTTX",
"RFC_ANEMIA",
"RFC_HEMO",
"COAGULATION_DISORDER",
"RFC_RHS",
"RFC_ISO",
"BILARY_LIVE_DISORD",
"RFC_CDDZ",
"RFC_CVDZ",
"RFC_APSY",
"RFC_CVSPEC",
"RFC_ASTH",
"RFC_LGDZ",
"RENAL_DISORDER_DISEASE",
"RFC_RNDY",
"RFC_THYDZ",
"RFC_CA",
"CANCER_TREATMENT" )
),       


)

server <- function(input, output) {

}
# Run the application 
shinyApp(ui = ui, server = server)

只需添加一个downloadButton和相应的downloadHandler:

library(shiny)
ui <- fluidPage(
titlePanel(h1(" Birth Worksheet", align = "center")),
hr(),
sidebarPanel(
titlePanel(h4("Antenatal Risk Factors/Current Pregnancy", align = "center")),
hr(),
checkboxGroupInput("Antel", "  ",
choiceNames =
list(
"Urinary tract infections this pregnancy",
"Urinary tract infections this pregnancy, treated",
"Anemia this pregnancy (HCT < 30/Hgb <10)",
"Hemoglobinopathy this pregnancy",
"Coagulation disorder",
"Rh sensitization",
"Other iso-immunization",
"Biliary/liver disorder(Yes at delivery)",
"Cardiac disease",
"Autoimmune disease",
"Antiphospholipid syndrome",
"Specify collagen vascular disease",
"Asthma",
"Acute or chronic lung disease",
"Renal disorder/disease",
"Renal dialysis or end stage renal disease",
"Thyroid disease",
"Cancer this pregnancy",
"Cancer treatment this pregnancy"
),
choiceValues = list(
"RFC_INFUT", "RFC_INFUTTX",
"RFC_ANEMIA",
"RFC_HEMO",
"COAGULATION_DISORDER",
"RFC_RHS",
"RFC_ISO",
"BILARY_LIVE_DISORD",
"RFC_CDDZ",
"RFC_CVDZ",
"RFC_APSY",
"RFC_CVSPEC",
"RFC_ASTH",
"RFC_LGDZ",
"RENAL_DISORDER_DISEASE",
"RFC_RNDY",
"RFC_THYDZ",
"RFC_CA",
"CANCER_TREATMENT"
)
),
downloadButton("download_checkboxes")
)
)

server <- function(input, output) {
output$download_checkboxes <- downloadHandler(
filename = function() {
"checkboxes.csv"
},
content = function(file) {
data <- data.frame(selected = input$Antel)
write.csv(data, file, row.names = FALSE)
}
)
}
# Run the application
shinyApp(ui = ui, server = server)

最新更新