R Shiny bad dependency from for loop variable. Is there a way to force evaluation?

前端 未结 1 731
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 14:46

A simple way to replicate this issue:

shinyApp(
  ui = fluidPage(
    textOutput(\"helloJohn\"),
    br(),
    textOutput(\"helloJacob\"),
    br(),
    tex         


        
相关标签:
1条回答
  • 2021-01-15 15:17

    You can wrap what's in the for loop in local and create a local variable name2 that receives name.

    for(name in c("John", "Jacob", "Joe")) {
      local({
      name2 <- name
      output[[paste0("hello", name2)]] <- renderText({paste0("hello ", name2, "!")})
      })
    }
    

    Additional info and inspiration for this answer here.

    0 讨论(0)
提交回复
热议问题