Can anyone please tell me how can we define a global variable with string data type in RShiny app.
I tried below syntax but it's throwing error:
i <- "Alpha"
lvl <- reactiveVal()
lvl(i)
Can anyone please tell me how can we define a global variable with string data type in RShiny app.
I tried below syntax but it's throwing error:
i <- "Alpha"
lvl <- reactiveVal()
lvl(i)
You have to put the value which you want to assign to lvl
inside reactiveVal
. Then you can access this value via lvl()
. Try this:
library(shiny)
ui <- fluidPage(
textOutput("var")
)
server <- function(input, output, session) {
i <- "Alpha"
lvl <- reactiveVal(i)
output$var <- renderText(lvl())
}
shinyApp(ui, server)