I would like to run R code in two locations, in an Rnw file and as an interactive shiny R markdown document.
Thus, what I need, since interactive shiny components do not work in Rnw files, is a code snippet in R that detects whether to load the interactive code or not.
This seems to work, but it feels like a quick hack:
if (exists("input")) { # input is provided by shiny
# interactive components like renderPlot for shiny
} else {
# non-interactive code for Rnw file
}
Is there a stable solution or something like a global variable that I can access that says whether shiny is running at the moment? Or should I check whether the shiny
package is loaded?
What's safest?
.Rmd
and the static components into the.Rnw
is not an option? – Bernsif (interactive())
do the job? It checks if you are in an interactive session or not. If not (e.g. you are in a document) it would return your non-interactive code. – Berns.Rmd
withruntime: shiny
. Bummer. – Berns