How to set global variable values ​​in onStart parameter for Shiny app

I'm trying to use the onStart parameter for the shinyApp function from the R shiny package to set global variables instead of using the global.R file. So the format would be

shinyApp(onStart = ..., ui = ..., server = ...)

      

However, I am unable to set global variables. For example, if I do the following:

shinyApp(
    onStart = function() { 
          temp1 <- 2
          temp2 <- 3
          temp3 <- 4
    },
    ui = fluidPage(
         titlePanel("test"),
         mainPanel(uiOutput("test_slider"))),
    server = function(input, output, session) {
         output$test_slider <- renderUI({
         sliderInput("test_slider",
                     "Testing",
                     min = 0,
                     max = temp1 + temp2 + temp3 + temp4,
                     value = 0

         )
      })
    }
)

      

When I do this, I get the error "temp1 not found". I'm not too sure how to do this, so any suggestions or solutions would be greatly appreciated!

+3


source to share


1 answer


To assign global variables, you can use <<-

For example:



temp1 <<- 2

      

+4


source







All Articles