3

I am new to shiny, and building an app based on the answer to this question

But there is a section in the code I do not understand, and can not find more insight in shiny documents. In the code section below (part of the example), why the use of local? and the ii <- i assignment?

My apologies if this is not a proper stackoverflow question! this is my first one..

renderPlots <- function(n, input, output, prefix="plot") {
    for (i in seq.int(n)) {
        local({
            ii <- i  # need i evaluated here
            ## These would be your 10 plots instead
            output[[sprintf('%s_%g', prefix, ii)]] <- renderPlot({
                ggplot(dat, aes_string(x='time', y=input$var)) + rndmPlot(input)
            })
        })
    }
}
Community
  • 1
  • 1
SoCool
  • 31
  • 2
  • The answer is in [the gist](https://gist.github.com/wch/5436415) in the question that you linked. You need `local` to force evaluate the `i` to each element of the loop, else the `i` value will be the same across each plot. – Jake Kaupp Dec 29 '16 at 14:24

0 Answers0