I am looking for a way to assign values to output
on the fly.
The idea is that each time an action button is hit, a new render object (e.g. text_1
, text_2
, ...) is saved in output
. To achieve this I already have a variable which increases by one when the button is used. Now, I would like to use some constant string in addition with this variable to create a name for an output object (something like this paste0("output$text_",i)
. The problem I have is that I only know how to add something to output
with <-
. But this way I can't use a string as variable name (at least I think so). With assign
it did not work as well. Is there another way to do what I want?
library(shiny)
ui <- fluidPage(
textOutput("text_1")
textOutput("text_2")
)
server <- function(input, output) {
output$text_1<- renderText({ "Hi" }) #standard
assign(paste0("output$text_",2), renderText({ "Hello" }) ) #sth. I would like to do
}
shinyApp(ui = ui, server = server)