【问题标题】:Error in make.unique: 'names' must be a character vector when switching tabsetPanel in shinymake.unique 中的错误:在闪亮的 tabsetPanel 中切换时“名称”必须是字符向量
【发布时间】:2021-08-04 16:04:41
【问题描述】:

在下面的示例中,当在单选按钮 iris 和 About- 之间来回切换时,我多次打印以下错误-

Warning: Error in make.unique: 'names' must be a character vector
  [No stack trace available]

我已经找到了错误,但除了这些之外没有太多帮助(但是它们有点无关紧要):

  1. https://github.com/petzi53/bib2academic/issues/1
  2. https://github.com/satijalab/seurat/issues/1710
  3. how to solve "ERROR: Names must be unique." in r-package ggstatsplot?

为什么即使我只选择了一个,它也会显示我选择了两个输入?

[1] "You have chosen: 1"
[1] "You have chosen: 3" #this should have been NULL??!

还有为什么当我切换导航菜单时mainPanel 没有正确更新?

options(scipen = 99999, stringsAsFactors = FALSE)
library(shiny)
library(shinyjs)
library(shinyWidgets)
library(DT)
library(dplyr)

gen_rep_def <- data.frame(Report = c("iris",
                                     "etc"),
                          Purpose=c("abc",
                                    "xyz"))

mon_rep_def <- data.frame(Report = c("mtcars",
                                     "etc"),
                          
                          Purpose= c("abc",
                                     "xyz"))

ui <- fluidPage(
  
  shinyjs::useShinyjs(), 
  
  navbarPage( 
    
    verbatimTextOutput("value"),

    tabPanel("General Reports",
             
             sidebarLayout(

               sidebarPanel(
                 
                 id = "Sidebar",
                 
                 shinyWidgets::prettyRadioButtons(
                   inputId = "controller",
                   label = "Choose:", 
                   choices = c("About"= 1,
                               "iris"= 2),
                   icon= icon("check"),
                   selected = 1,
                   status = "success",
                   animation="smooth"
                 )
               ),
               
               mainPanel(
                 id = "main_panel",
                 
                 tabsetPanel(
                   id = "hidden_tabs",
                   type = "hidden",
                   tabPanelBody(
                     "panel1", DT::DTOutput('panel1_data')
                   ),
                   
                   tabPanelBody(
                     "panel2", 
                     tabsetPanel(
                       tabPanel("Data", DT::DTOutput('panel2_data'))
                     )
                   )
                 )
               )
             )
    ),
    
    # monthly reports
    tabPanel("Extra General Reports",
             
             sidebarLayout(

               sidebarPanel(
                 
                 id = "Sidebar_2",
                 
                 shinyWidgets::prettyRadioButtons(
                   inputId = "controller_2",
                   label = "Choose:", 
                   choices = c("About"= 3,
                               "mtcars"= 4),
                   icon= icon("check"),
                   #selected = 3,
                   status = "success",
                   animation="smooth"
                 )
               ),
               
               mainPanel(
                 id = "main_panel_2",
                 
                 tabsetPanel(
                   id = "hidden_tabs_2",
                   type = "hidden",
                   tabPanelBody(
                     "panel3", DT::DTOutput('panel3_data')
                   ),
                   
                   tabPanelBody(
                     "panel4", 
                     tabsetPanel(
                       tabPanel("Data", DT::DTOutput('panel4_data'))
                       )
                     )
                   )
                 )
               )
             )
    ),
    tags$head(tags$style(HTML('.navbar-brand {width: 270px; font-size:35px; text-align:left;
                              font-family: "serif";')))
  )

server <- function(input, output, session) {
  
  observeEvent(input$controller, {
    print(paste0("You have chosen: ", input$controller))
  })
  observeEvent(input$controller_2, {
    print(paste0("You have chosen: ", input$controller_2))
  })
  
  data_sets <- list(df1 = gen_rep_def, 
                    df2 = iris,
                    df3 = mon_rep_def, 
                    df4 = mtcars)
  
  data_to_use <- reactiveValues(name = "df", data = data.frame())
  
  
  observeEvent(input$controller, {
    
    updateTabsetPanel(session, inputId= "hidden_tabs", selected = paste0("panel", input$controller))
    
    req(input$controller)
    
    data_to_use$data <- data_sets[[as.numeric(input$controller)]]
    data_to_use$name <- names(data_sets[as.numeric(input$controller)])
    
    
    output[[paste0('panel',  input$controller, '_data')]] <- DT::renderDT(server = FALSE, {
      DT::datatable(data_to_use$data,
                    filter = 'top', 
                    extensions = 'Buttons')})
    
    
  })
  
  observeEvent(input$controller_2, {
    
    updateTabsetPanel(session, inputId= "hidden_tabs_2", selected = paste0("panel", input$controller_2))
    
    req(input$controller_2)
    
    data_to_use$data <- data_sets[[as.numeric(input$controller_2)]]
    data_to_use$name <- names(data_sets[as.numeric(input$controller_2)])
    
    output[[paste0('panel',  input$controller_2, '_data')]] <- DT::renderDT(server = FALSE, {
      DT::datatable(data_to_use$data,
                    filter = 'top', 
                    extensions = 'Buttons')})
    
    
  })
  
}

shinyApp(ui= ui, server= server)

【问题讨论】:

  • 你能减少代码的大小吗?这里似乎有很多不必要的东西。
  • 对于更新的示例,我没有看到任何错误,因此它可能来自您删除的行(可能来自esquisse 包?)。尝试从您的原始示例开始,逐部分删除行并检查哪一行引发了错误。关于控制台中的消息,当您运行应用程序时,在两个选项卡中都选择了“关于”按钮。这就是它打印 1 和 3 的原因。
  • 来自?shinyWidgets::prettyRadioButtonsselected参数对应于“最初应该选择的值,(如果没有指定则默认为第一个值)”,所以这里默认为3跨度>
  • 哦,哇,我明白了。如果您想提交参赛作品,我将给您答复。感谢您的时间朋友:) 欣赏它。
  • 我做的cmets并没有真正回答主要问题,即:如何解决标题中的错误信息?您应该尝试自己搜索(通过首先找到引发此错误的组件),如果找到解决方案,请将其作为答案发布。下次,也许你应该在单独的帖子中提出单独的问题,这样会更容易得到答案;)

标签: r shiny shiny-server dt shiny-reactivity


【解决方案1】:

不幸的是,错误来自 esquisse 包 (https://github.com/dreamRs/esquisse/issues/164)。现在已经被开发者解决了。

@bretauv 回答了我的问题的第二部分。再次感谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 2020-12-11
    • 2021-01-17
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多