make.unique 中的错误:'names' 在 shiny 中切换 tabsetPanel 时必须是字符向量
Error in make.unique: 'names' must be a character vector when switching tabsetPanel in shiny
在下面的示例中,当我在单选按钮 iris 和 About-
之间来回切换时多次打印以下错误
Warning: Error in make.unique: 'names' must be a character vector
[No stack trace available]
我已经查找了错误,但除此之外没有太多帮助(但它们有点无关紧要):
- 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?
为什么它打印我选择了两个输入,即使我只选择了一个?
[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
包 (https://github.com/dreamRs/esquisse/issues/164)。目前已由开发者解决。
@bretauv 回答了我问题的第二部分。再次感谢!
在下面的示例中,当我在单选按钮 iris 和 About-
之间来回切换时多次打印以下错误Warning: Error in make.unique: 'names' must be a character vector
[No stack trace available]
我已经查找了错误,但除此之外没有太多帮助(但它们有点无关紧要):
- 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?
为什么它打印我选择了两个输入,即使我只选择了一个?
[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
包 (https://github.com/dreamRs/esquisse/issues/164)。目前已由开发者解决。
@bretauv 回答了我问题的第二部分。再次感谢!