首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用RShiny下载checkBoxGroup检查列表的csv文件

如何使用RShiny下载checkBoxGroup检查列表的csv文件
EN

Stack Overflow用户
提问于 2022-06-15 06:20:53
回答 1查看 26关注 0票数 0

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

代码语言:javascript
运行
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-15 07:15:48

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

代码语言:javascript
运行
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72626700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档