rstudio / shinydashboard

Shiny Dashboarding framework
https://rstudio.github.io/shinydashboard/
Other
893 stars 298 forks source link

`shinydashboard::updateTabItems` not matching `shiny::updateTabsetPanel` #397

Open Mosk915 opened 1 year ago

Mosk915 commented 1 year ago

According to this line, the function updateTabItems is exactly the same function as shiny::updateTabsetPanel. https://github.com/rstudio/shinydashboard/blob/7ccaacce9a5ec76ff204229385d724b6b9e0b82f/R/tabs.R#L83

The problem is that if the function shiny::updateTabsetPanel were to change, which it did when going from version 1.5.0 to version 1.6.0 of shiny, the function updateTabItems would not also change since it is set at the time the package is compiled. This is problematic when using an renv package cache or when deploying content to Posit Connect which also uses a package cache since there is only one installation of a given version of a package.

This can result in unexpected behavior, where the two function definitions will not match:

> shiny::updateTabsetPanel
function (session = getDefaultReactiveDomain(), inputId, selected = NULL) 
{
    validate_session_object(session)
    message <- dropNulls(list(value = selected))
    session$sendInputMessage(inputId, message)
}
> shinydashboard::updateTabItems
function (session, inputId, selected = NULL) 
{
    message <- dropNulls(list(value = selected))
    session$sendInputMessage(inputId, message)
}

Here is a complete set of steps for how to reproduce the issue in an R project.

  1. Create a project in RStudio or Workbench with renv enabled. Set the renv setting use.cache to false.

  2. Restart R.

  3. Install devtools install.packages("devtools", repos = "cran.rstudio.com")

  4. Restart R.

  5. Install shiny 1.5.0 devtools::install_version("shiny", "1.5.0", repos = "cran.rstudio.com")

  6. Restart R.

  7. Verify shiny::updateTabsetPanel does not have the default set for session in the function definition.

  8. Install shinydashboard 0.7.1. Don’t upgrade any other packages when prompted. devtools::install_version("shinydashboard", "0.7.1", repos = "cran.rstudio.com")

  9. Restart R.

  10. Verify shinydashboard::updateTabItems does not have the default set for session in the function definition.

  11. Restart R.

  12. Install shiny 1.6.0 devtools::install_version("shiny", "1.6.0", repos = "cran.rstudio.com")

  13. Restart R.

  14. Verify shiny::updateTabsetPanel does have the default set for session in the function definition.

  15. Verify shinydashboard::updateTabItems still does not have the default set for session in the function definition.

  16. Restart R.

  17. Reinstall shinydashboard 0.7.1. Don’t upgrade any other packages when prompted. devtools::install_version("shinydashboard", "0.7.1", repos = "cran.rstudio.com")

  18. Restart R.

  19. Verify shinydashboard::updateTabItems now does have the default set for session in the function definition.

Perhaps a better way to implement the function would be as follows:

updateTabItems <- function(...) {
   shiny::updateTabsetPanel(...)
}
Rikagx commented 1 year ago

There is from Posit support ticket # 95105 which has more information.

gadenbuie commented 1 year ago

Thanks! I implemented the suggested fix in #398