loading...

Shiny applications can be embedded in certain R Markdown documents. However, the application is automatically loaded at the same time as the main page, and that may not be the desired behavior. With launch_shiny(), you display just a screenshot of the Shiny application in the page. The user has to click on it to actually launch the application (that replaces the screenshot on the page).

launch_shiny(
  url,
  app = sub("\\?.+$", "", basename(url)),
  imgdir = "images/shinyapps",
  img = paste0(imgdir, "/", app, ".png"),
  createimg = TRUE,
  width = 780,
  height = 500,
  fun = NULL,
  alt1 = "*Click to start the Shiny application.*",
  alt2 = paste0("*Click to start",
    "or [run `{run.cmd}`]({run.url}{run.arg}){{target=\"_blank\"}}.*"),
  toc = "",
  toc.def = "Shiny application {app}",
  run.url = "start_rstudio.html?runrcode=",
  run.cmd = glue("{fun}(\"{app}\")"),
  run.arg = URLencode(run.cmd, reserved = TRUE),
  app.img = "images/list-app.png",
  app.link = "shiny_app",
  ...
)

Arguments

url

The URL of the Shiny application. If both app = and baseurl = are provided, you don't need to specify it.

app

Name of the shiny application (cannot be duplicated on a page).

imgdir

The directory without trailing "/" where images relative to Shiny applications are stored. By default, it is relative to current directory, in images/shinyapps subdirectories.

img

The relative or absolute path to the image with a screenshot of the Shiny application, as produced by webshot_shiny().

createimg

If the app image (img) is not found, and there is no default image in imgdir =, do we put it there (yes be default)?

width

The width of the image and iframe for the app.

height

The height of image and iframe.

fun

The function to run as alternative to start the Shiny application locally. It is better to fully specify it (package::function), and it should take one argument which is the application name in app =.

alt1

Alternate text to display at the bottom of the screenshot when nothing is provided for fun =. If NULL, nothing is displayed below the screenshot.

alt2

Alternate text to display at the bottom of the screenshot in case fun = is provided.

toc

Entry to use in the exercises table of content (NULL if no entry, "" for a default entry based on toc.def =).

toc.def

Text for a default toc entry using glue() syntax for replacement, e.g., {app}.

run.url

The URL to use to start the Shiny application in RStudio server in the SciViews Box. It should generally end with ?runrcode=, and the R code to execute will be appended to it from run.arg =.

run.cmd

The command to use to launch the Shiny application in RStudio.

run.arg

The URL encoded version of run.cmd =.

app.img

The image to display in front of the toc entry

app.link

The link when the image is clicked (sends to an help page about Shiny applications).

...

Not used here, but it allows to add more arguments used by the screenshot addin, like delay =, offsetx = or offsety =, see webshot_shiny().

Value

The HTML content that creates the image and the iframe. The function must be called from within an R inline expression or from an R chunk with results='asis' in an HTML-rendered version of the R Markdown document to get the correct result.

See also

Examples

# TODO...