Shiny to Markdown - adressing objects with get function

Viewed 32

I have built a shiny app and want to use the reactive functions in a markdown code. Download handler looks as follows, so no change in environment:

output$Report <- downloadHandler(
        filename = function() {
            paste('Report.pdf')
        },
        
        content = function(file) {
            src <- normalizePath('report.Rmd')
            
            # temporarily switch to the temp dir, in case you do not have write
            # permission to the current working directory
            owd <- setwd(tempdir())
            on.exit(setwd(owd))
            file.copy(src, 'report.Rmd', overwrite = TRUE)
            
            library(rmarkdown)
                        
            out <- render('report.Rmd', pdf_document()) 
            file.rename(out, file)
        }
    )

If im adressing my objects directly by:

summary(Model_1())

It´s working fine. But if I want to put this in a function and getting the object with:

summary(get(paste0("Model_1()")))

Markdown cannot find the object. Since I have a highly dynamic shiny app, I want to get the summary by something like this:

function(i){
summary(get(paste0("Model_",i,"()")))

Also tried to pass the Model_1() with a params list to markdown and get it, but it didn´t work. Don´t understand why get() has problems while direct adressing the object is working. Can anyone explain the reason for that to me or has an alternative to get()?

Thanks! best Marcel

1 Answers

You need to pass the name of the object you want to access to get(). The parentheses for accessing the value of a reactive are not part of that. Try summary(get("Model_1")()) instead.

Related