teal icon indicating copy to clipboard operation
teal copied to clipboard

[Feature Request]: teal::init to return shinyApp instead of a list

Open gogonzo opened this issue 2 years ago • 4 comments

teal::init to return "teal_app" object (simple S3 class). For this class we can have a print method which can look as follows:

print.teal_app <- function(x, ...) {
  cat("teal app <more information about the app>")
  shiny::shinyApp(x$ui, x$srv) 
}

Thanks to above "teal_app" object will preserve previous features (list of ui, server, ui_args, ... etc) and could be run without shinyApp(x$ui, x$server) . This would shorten the apps code:

# from
app <- teal::init(...)
shinyApp(app$ui, app$server)

# to
teal::init(...)

With the S3 class first and the second in above code would be possible.

Alternatively, print.teal_app could just print information about the app with note use shinyApp(x$ui, x$server) to run the app.

Please note that shiny works in very similar way https://github.com/rstudio/shiny/blob/370ba1f288d3f759456ef3ef6e768ee1d7fda677/R/shinyapp.R#L552

gogonzo avatar Sep 08 '23 06:09 gogonzo

Do you mean just adding shinyApp(ui = res$ui, server = res$server) as the return value of init?

Nothing will be broken due to this,

Besides the fact that you can't do shinyApp(app$ui, app$server) anymore, do I have this correct?

chlebowa avatar Nov 17 '23 08:11 chlebowa

This is a potentially breaking change and if done (which I am still not sure about) it would be better to go through the formal deprecation process

pawelru avatar Nov 17 '23 08:11 pawelru

@chlebowa @pawelru true, I have not noticed shinyApp doesn't return a list. Forget about this.


Initially I thought that teal::init can return list(ui = ui, server = sever, class = "teal.app") and we can have a print.teal.app which runs the app. Since it is not so easy I don't push for this and I suggest to refine this first ;)

gogonzo avatar Nov 17 '23 08:11 gogonzo

I don't think we should return shiny.appobj from teal::init() if we did this we would have to support other arguments to be passed into init like enableBookmarking. I misinterpreted the feature request when I first read it. I just thought that we're replacing the runApp(app) into shinyApp(app$ui, app$server) in all examples where we use the former as it is meant for interactive calling of shiny app and has known problems when it comes to deployment.

vedhav avatar Nov 17 '23 13:11 vedhav

The idea doesn't make sense. Let's pay attention to https://github.com/insightsengineering/teal/issues/1448

gogonzo avatar Feb 05 '25 05:02 gogonzo