bookmark problem with list vs. function

Hi,

I was finally able to come up with a minimal example...

In the code below I am using either a list with a function (LIST(inputTab())) directly (this works) or the same list inside a variable of type list. The resulting tag/list is the same. For me, there is really no difference between the two.

But, what happens is that (with URL or server mode) a bookmark is created but, when used it either it correctly sets the old selection or it defaults to the default value.

Any help / comment is appreciated.

( I need to pass the variable version as I am producing a list dynamically.)

Thx
Bernd

library(shiny)
library(shinydashboard)

mulist <- list(inputTab())
# base::source(file = "inst/develo/bookmarkUI.R", local = TRUE)
inputTab <- function(){
  shinydashboard::tabItem(
    tabName = "input",
    radioButtons("whichscLog",
                 label = "Compute normalizations?",
                 choices = c(
                   "disable log" = "disablescEx_log",
                   "use scEx from loaded data" = "useLog",
                   "calculate normalization here" = "calcLog"
                 ),
                 selected = "disablescEx_log"
    )
  )
}

ui <- function(request) {
  shinyUI(
    shinydashboard::dashboardPage(
      shinydashboard::dashboardHeader(title = "SCHNAPPs"),
      shinydashboard::dashboardSidebar(
        # sideBar()
        shinydashboard::sidebarMenu(
          id = "sideBarID",
          shinydashboard::menuItem("input",
                                   # id="inputID",
                                   tabName = "input", icon = icon("folder")
          ),
        bookmarkButton()
        )), # dashboard side bar
      shinydashboard::dashboardBody(
        tags$div(
          class = "tab-content",
######## Problem area, mulist doesn't work, list(inputTab()) works
          # mulist
          list(inputTab())
#######

        )
      )
   )
  )
  }

server <- function(input, output, session) {
}

sa = shinyApp(ui, server, enableBookmarking = "url")
runApp(sa)

1 Like

Hi, Bernd. Thanks for the reprex, it's almost perfect. It's just missing

library(shiny)
library(shinydashboard)

at the top. The best self-check is highlighting the entire example in RStudio and CTRL or CMD ENTER or installing the reprex package which will show up in the addins drop down (you may have to enter rep in the search box to get it to come up).

Fortunately, although I'm not a bright shiny object myself (not at all experienced in shiny and .., well, never mind), I was able to eyeball the problem. You want

mulist()

with the parens. At least I think it worked the same.

Hi Richard,
thanks for the comments. I added the library statements and tried your solution.

Unfortunately, mulist is a list and not a function, thus, I get the following error message:

> mulist()
Error in mulist() : could not find function "mulist"
1 Like

Ah, got you. (Warned you about shiny.)

So mulist is some markup language packed in a list. (D'oh)

Since I'm not sure what the result is supposed to look like, I'm unsure. But keeping mulist as before and changing the function per

# base::source(file = "inst/develo/bookmarkUI.R", local = TRUE)
inputTab <- function(mulist){ ...

runs.

They all work, in the sense that that the GUI is built and the selection is working as well. What is not working is the bookmarking. To be explicit, select the 2nd or 3rd option and then click on the bookmark button. Use the link generate in a different window/browser and the same selection should be retained.
=> if it is not working the 1st option is selected.

Here are a few other options I have tried:

mulist <- list(inputTab()) # not working
mulist2 <- function(mulist){mulist} # not working
mulist3 <- function() {list(inputTab())} # working
mulist4 <- function() {mulist} # not working

When using bookmarking, all of your UI must be creating inside the UI function:

This is needed because bookmarks have to replay the bookmarked values: effectively, Shiny modifies the default value for each input control. This means there’s no longer a single static UI but multiple possible UIs that depend on parameters in the URL.

(from Chapter 11 Bookmarking | Mastering Shiny)

Because you're generating the HTML outside of the UI function, shiny can no longer modify the default value, and hence bookmarking will not work.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.