3

In the example below I get following error many times printed when switching back and forth between radio buttons iris and About-

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

I have looked for the error, but not much of help is out there besides these (however they're a bit irrelevant):

  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?

Why does it print that I have selected two inputs, even though I have selected only one?

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

Also why is the mainPanel not updating properly when I switch the nav menus?

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)
bretauv
  • 7,756
  • 2
  • 20
  • 57
AOE_player
  • 536
  • 2
  • 11
  • Could you reduce the size of the code? There seems to be a lot of unnecessary stuff here. – bretauv May 16 '21 at 11:13
  • @bretauv, apologies for overdoing in the reproducible example. I didn't know which thing was throwing the error. Please see the updated example. I only left materials to produce the error. Thanks! – AOE_player May 16 '21 at 17:48
  • 1
    With the updated example, I don't see any error so it was probably coming from the lines you removed (maybe from the `esquisse` package?). Try to start with your original example, remove the lines part by part and check which line was throwing the error. Concerning the messages in the console, when you run the app, the button "About" is selected in both tabs. This is why it prints 1 and 3. – bretauv May 16 '21 at 18:12
  • @bretauv Hmmm....Thank you. You're right! One question, I have commented out input 3, so why is it being selected on start? I assumed that `[No stack trace available]` was appearing from `mainPanel` not able to render two inputs. However, `esquisse` has to do with that. – AOE_player May 16 '21 at 18:35
  • 1
    From `?shinyWidgets::prettyRadioButtons`: the `selected` argument corresponds to "The values that should be initially selected, (if not specified then defaults to the first value)", so it defaults to 3 here – bretauv May 16 '21 at 18:50
  • 1
    Ohhh wow, I see. I would award an answer to you if you would like to submit an entry. Thanks for your time friend :) Appreciate it. – AOE_player May 16 '21 at 18:51
  • 1
    The comments I made don't really answer the main question, which is: how to solve the error message in the title? You should try searching that by yourself (by finding the component that throws this error first), and if you find the solution, post it as an answer. Next time, maybe you should ask separate questions in separate posts, it will be easier to have answers ;) – bretauv May 16 '21 at 18:57
  • Got it got it. Will keep that in mind. Take care and stay safe ;) – AOE_player May 16 '21 at 19:02

1 Answers1

0

The error was coming from the esquisse package unfortunately (https://github.com/dreamRs/esquisse/issues/164). It has been resolved now by the developer.

And second part of my question was answered by @bretauv. Thank you again!

AOE_player
  • 536
  • 2
  • 11