简体   繁体   中英

How to Set Global Variable Values in the onStart parameter of Shiny Application

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

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

However, I cannot seem to be able 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 'object temp1 not found'. I am not too sure how to make this work, so any suggestions or solutions would be greatly appreciated!

要分配全局变量,可以使用<<- Eg:

temp1 <<- 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM