Skip to content

[Question]: How to properly add examples so shinylive works properly? #5

@vedhav

Description

@vedhav

What is your question?

Based on the readme I tried the following steps:

  1. Installed the roxy.shinylive
  2. Edited the DESCRIPTION file with roxygen: list(markdown = TRUE, packages = c("roxy.shinylive"))
  3. In one of the examples (example_module), I included the @examplesShinylive tag.
  4. Of course I had to run the docs via a static server to make it work so I did that using httpuv::runStaticServer(dir = "/Users/vedha/insightsengineering/teal/docs/"). Would be nice to mention this in the docs so people don't get confused when they don't see this working when opening the static HTML file like they're used to. I see that this is just an iframe embed so there is no need to serve it.

This had a few small issues with how the examples were written and to make it work I had to make sure that:

  1. The library(teal) was called in the example. Should we have a hook to call the package before running any example?
  2. Since the shinyApp() was run inside the if (interactive()) it did not work unless I changed the if condition to something like this interactive() || !is.null(getOption('webr_pkg_repos')) (not recommending this, I was just testing)
  3. The iframe width of 140% seems to overlap and cause layout issues for me. I don't understand why we have this.
  4. It would be nice if we display the shinylive app below the example code.

The final example roxygen code looked like this in my case:

#' @inheritParams teal_modules
#' @return A `teal` module which can be included in the `modules` argument to [init()].
#' @examplesShinylive
#' @examples
#' 
#' library(teal)
#' app <- init(
#'   data = teal_data(IRIS = iris, MTCARS = mtcars),
#'   modules = example_module()
#' )
#' if (interactive() || !is.null(getOption('webr_pkg_repos'))) {
#'   shinyApp(app$ui, app$server)
#' }
#' @export

So, I'm looking for a better way to write examples, or add supporting hooks to make it easier to use this package.

Screenshot 2024-09-23 at 3 52 54 PM

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions