-1

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)

1 Answers1

0

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)
stefan
  • 90,330
  • 6
  • 25
  • 51