launch_shiny | R Documentation |
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 = 790,
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",
...
)
url |
The URL of the Shiny application. If both |
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 |
img |
The relative or absolute path to the image with a screenshot of
the Shiny application, as produced by |
createimg |
If the app image ( |
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 ( |
alt1 |
Alternate text to display at the bottom of the screenshot when
nothing is provided for |
alt2 |
Alternate text to display at the bottom of the screenshot in case
|
toc |
Entry to use in the exercises table of content ( |
toc.def |
Text for a default toc entry using |
run.url |
The URL to use to start the Shiny application in RStudio
server in the SciViews Box. It should generally end with |
run.cmd |
The command to use to launch the Shiny application in RStudio. |
run.arg |
The URL encoded version of |
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 |
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.
webshot_shiny()
# TODO...
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.