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):
- https://github.com/petzi53/bib2academic/issues/1
- https://github.com/satijalab/seurat/issues/1710
- 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)