Object not found in function

Hello, I've been trying to define an object that the function below can find, I believe I am doing it, but i still get an error message saying that "userInputs is not found"

Here is the relevant server code

final <- reactiveValues()

observeEvent(input$getUserTable, {

userInputs <- list(focus = 1, school = c(10101, 10102), data = c(101, 102, 301))
l <- length(userInputs)
final$userTable <- filterDatabase(l)

})

and here is the function filterDatabase()

filterDatabase <- function(x) {
if (x == 1) {
filter(freshDatabase2[['count']], eval(str2expression(paste(names(userInputs)[1], 'ID', sep = ''))) %in% userInputs[[1]])
} else {
filter(filterDatabase(x-1), eval(str2expression(paste(names(userInputs), 'ID', sep = ''))) %in% userInputs[])
}
}

First an example of an app that doesnt work

library(shiny)

ui <- fluidPage(
  verbatimTextOutput("showit")
  actionButton("mybutton")
)

server <- function(input, output, session) {
  
  observeEvent(input$mybutton,
               {
                 userinfo <- list(1,2)
               })

  output$showit <- renderPrint({
    userinfo 
  })
}

shinyApp(ui, server)

fixed:

library(shiny)

ui <- fluidPage(
actionButton("mybutton",label="push"),
verbatimTextOutput("showit"))

server <- function(input, output, session) {
  userinfo <- reactiveVal(NULL)
  observeEvent(input$mybutton,
               {
                 userinfo(list(1,2))
               })
  
  output$showit <- renderPrint({
    userinfo()
  })
}

shinyApp(ui, server)

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.