首页 > 解决方案 > 使用 updatePrettyCheckboxGroup 时不应用 prettyCheckboxGroup 的格式选项

问题描述

我正在编写一个闪亮的应用程序,其中prettyCheckboxGroup选项由用户上传的 .csv 文件填充。如果我手动设置choices(例如“A”、“B”、“C”),那么我可以更改statusshapeoutline等。但是,如果我在服务器代码中使用updatePrettyCheckboxGroup基于 an observeEvent,那么结果就是默认样式.

ui <- navbarPage("Tabbed page",
                 tabPanel("Works",
                          prettyCheckboxGroup(
                            inputId = "Id001",
                            label = "Checkboxes with status",
                            choices = c("A", "B", "C"),
                            inline = TRUE,
                            status = "danger",
                            shape = "round"),

                 ),
                 tabPanel("Doesn't Work",
                          fileInput("Line_Dataset", label = "Choose Data"),                    
                          prettyCheckboxGroup(
                            inputId = "Broken",
                            label = "Checkboxes with status", 
                            choices = NULL,
                            inline = TRUE,
                            status = "danger",
                            shape = "round"),
                 )
)

server <- function(input, output, session) {
  LineFile <- eventReactive(c(input$Line_Dataset), {
    read_csv(input$Line_Dataset$datapath, col_names = T)
  })
  
  observeEvent(input$Line_Dataset,
               {elements_line_data <- LineFile() %>%
                 colnames()
               
               updatePrettyCheckboxGroup(session,
                                         "Broken",
                                         choices = elements_line_data)
               })
  
}
shinyApp(ui,server)

使用 updatePrettyCheckboxGroup 时应该将status和参数放在哪里?shape他们需要进入服务器文件吗?

请注意,我在尝试使用时得到了相同的结果awesomeCheckboxGroupupdate...但由于格式化选项的数量,我选择使用 pretty。

谢谢,杰里米

PS 我很抱歉没有提供 .csv 但任何文件都可以使用

编辑:问题的截图。我希望“不起作用”选项卡中的复选框按钮看起来与“工作”中的相同。 在此处输入图像描述

标签: rshinyshinywidgets

解决方案


该函数updatePrettyCheckbox()无法传递参数状态和形状,因此生成正确复选框的唯一选项是直接使用renderUI(). 无论如何,问题是因为这两个参数在updatePrettyCheckbox()被调用时不存在,所以重新呈现了默认格式。

library(shiny)
library(shinyWidgets)
library(tidyverse)

ui <- navbarPage("Tabbed page",
                 tabPanel("Works",
                          prettyCheckboxGroup(
                              inputId = "Id001",
                              label = "Checkboxes with status",
                              choices = c("A", "B", "C"),
                              inline = TRUE,
                              status = "danger",
                              shape = "round")
                          
                 ),
                 tabPanel("Doesn't Work",
                          fileInput("Line_Dataset", label = "Choose Data"),
                 uiOutput('download_with_prettychbx')
                 )
)

server <- function(input, output, session) {
    LineFile <- eventReactive(c(input$Line_Dataset), {
        read_csv(input$Line_Dataset$datapath, col_names = T,)
        
    })
    
    
    
    observeEvent(input$Line_Dataset, {
    
        elements_line_data <- LineFile() %>%
            colnames()

    output$download_with_prettychbx <- renderUI({
    tagList(
                        
    prettyCheckboxGroup(
        inputId = "Broken",
        label = "Checkboxes with status", 
        choices = LineFile(),
        inline = TRUE,
        status = "danger",
        shape = "round")
    )
              
                 })})
    
}
shinyApp(ui,server)

推荐阅读