9

I have a select box in a app which I am trying to use outputOptions so that it will render all the tabs in my report generated using . Below is the code for that:

observeEvent(input$tab, {
  if (input$tab == "fruits"){
    choices <- c(
      "Apples",
      "Oranges"
    )
  }
  else if (input$tab == "vegetables") {
    choices <- c(
      "potatoes",
      "squash"
    )
  }

  else {
    choices <- c(
      "berries",
      "onions"
    )
  }
  updatePickerInput(session,
                    inputId = "selected_metric",
                    choices = choices)
})

outputOptions(output, "selected_metric", suspendWhenHidden = FALSE)

The following is the error I get

Error in .subset2(x, "impl")$outputOptions(name, ...) : selected_metric is not in list of output objects

massisenergy
  • 1,764
  • 3
  • 14
  • 25
SNT
  • 1,283
  • 3
  • 32
  • 78
  • 2
    `selected_metric` is an `input` object, which you've clearly demonstrated in `updatePickerInput(session, *inputId* = "selected_metric", choices=choices)`. `outputOptions`, which impact output objects won't affect input objects. What is the actual problem you're trying to solve? – tblznbits Oct 03 '18 at 14:38
  • What would be my options to get `outputoptions` as well as `select` – SNT Oct 03 '18 at 14:40
  • 1
    I don't understand your question. What are you trying to do? – tblznbits Oct 03 '18 at 14:41
  • I have a select box used across various tabs in a shiny app. Also I am trying to generate a report using markdown. It will generate only for the tab which I am currently on and not for all tabs.So in order to do that I am using outputOptions for all my select dropdowns to initiate them .With that all my tables across all tabs will have values and downloaded in the report. – SNT Oct 03 '18 at 14:45
  • You wouldn't want to use `outputOptions` on your `selectInput` then; you'd want to use it on the tables that are in each of your tabs. So, something like `outputOptions(session, 'my_tab1_table', suspendWhenHidden=FALSE)`. – tblznbits Oct 03 '18 at 14:48
  • I think I understand what you're trying to do. Why are you complicating things by trying to have the same `selectInput` across all tabs when you could have a unique `selectInput` on each tab. Then, you'd just pass those inputs in as parameters to your report and each of the tables would be created that way. This way, you prevent the need to find a way for Shiny to dynamically loop through each tab and grab the results. – tblznbits Oct 03 '18 at 14:57
  • @brittenb I have 10 tabs and 4 selectInput in each tab – SNT Oct 03 '18 at 15:02
  • you've seen [this example](https://shiny.rstudio.com/gallery/generating-reports.html) before, right? What I'm envisioning is that you'd just pass in all of the values of your inputs and then you'd have a template `.Rmd` file that would take those inputs and generate the tables on the fly in the report, instead of trying to read them from Shiny. – tblznbits Oct 03 '18 at 15:05
  • I understand the option provided above. But it is just now filtering out the data and passing them to report. It has analysis based on input which is what I am showing in the tables in shiny app. Based on what I understand you are suggesting to do that in the rmd. – SNT Oct 03 '18 at 17:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181239/discussion-between-brittenb-and-snt). – tblznbits Oct 03 '18 at 17:24
  • Please, close the topics if they're resolved – Elie Ker Arno Apr 20 '20 at 09:50
  • You can use updateSelectInput in the server code to render your choices: updateSelectInput(session, "inSelect", label = paste("Select input label", length(x)), choices = x, selected = tail(x, 1) ) – JamBelg Dec 21 '22 at 13:47

0 Answers0