Description
Hello,
Currently, if you have a navBarPage or a page_navbar and you do an insertTab or insert_nav in the following situation, the navbar's input$id variable does not take into account inserted panels.
I couldn't find a way to explain the problem without using a video.
The error was caught when the app is deployed to Posit Connect. As seen in the video at 1 second, I have a navBar which has three navs (Nav 0 is inserted into ui at initialization and the others via nav_insert) and when one of the navs is clicked it throws an alert with the name of the active nav. This was done by looking at the input$id of the navbar which in this case is called input$test and sending a message to js via session$sendCustomMessage.
At 11 seconds I go to another web page and return to the app with the browser arrows before Posit Connect kills the process. When I go back to the app I see that clicking on all the navs returns the name.
The problem: At 21 seconds I go to another web page and wait for Posit Connect to finish the process. In the second 47 I return to the application with the arrows of the browser. When I go back to the app I see that clicking on nav 1 and nav 2 does not return the name.
Test.Insert.Navs.mp4
Here is the application code:
library(shiny)
library(bslib)
ui <- page_navbar(
id = "test",
title = "Test Insert Navs",
header = tagList(
htmltools::tags$script(
"Shiny.addCustomMessageHandler('active_nav', function(data) {",
"alert(data.value);",
"});",
)
),
nav(
"Nav 0"
)
)
server <- function(input, output,session) {
nav_insert(id = "test", nav = nav(
"Nav 1"
), select = FALSE)
nav_insert(id = "test", nav = nav(
"Nav 2"
), select = FALSE)
observeEvent(input$test,{
session$sendCustomMessage(
type = "active_nav",
message = list(value = input$test)
)
})
}
shinyApp(ui = ui, server = server)
Next I leave the information of the computer from where the application was deployed.
R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Colombia.utf8 LC_CTYPE=Spanish_Colombia.utf8
[3] LC_MONETARY=Spanish_Colombia.utf8 LC_NUMERIC=C
[5] LC_TIME=Spanish_Colombia.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bslib_0.4.2 shiny_1.7.4
loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 jquerylib_0.1.4 compiler_4.2.3 later_1.3.0
[5] shinyjs_2.1.0 tools_4.2.3 odbc_1.3.4 digest_0.6.31
[9] bit_4.0.5 memoise_2.0.1 jsonlite_1.8.4 lifecycle_1.0.3
[13] lattice_0.21-8 pkgconfig_2.0.3 rlang_1.1.0 DBI_1.1.3
[17] cli_3.6.1 rstudioapi_0.14 fastmap_1.1.1 withr_2.5.0
[21] fs_1.6.1 vctrs_0.6.1 htmlwidgets_1.6.2 sass_0.4.5
[25] hms_1.1.3 bit64_4.0.5 grid_4.2.3 fontawesome_0.5.0
[29] R6_2.5.1 pool_1.0.1 blob_1.2.4 magrittr_2.0.3
[33] promises_1.2.0.1 htmltools_0.5.5 ellipsis_0.3.2 rsconnect_0.8.29
[37] mime_0.12 xtable_1.8-4 httpuv_1.6.9 shinybusy_0.3.1.9000
[41] cachem_1.0.7 zoo_1.8-12
Regards,