The help page for runApp
says:
Runs a Shiny application. This function normally does not return; interrupt R to stop the application (usually by pressing Ctrl+C or Esc).
Does "normally" mean "always"? Is there any way to add an "exit" button and return a value to the R session that called runApp
? Even if it's a hack, this would be convenient functionality. I've tried some searching but haven't found anything. I've also looked at the source for runApp
, the last line is return(.globals$retval)
, so it looks like there should be a way.
Can I set .globals$retval
directly and then call some kind of interrupt? Is there a function in the shiny
package that does this?
The official way of ending Shiny (http://rstudio.github.io/shiny/tutorial/#run-and-debug) requires interrupting R by typing Esc or clicking Stop, which also terminates the execution of the calling script.
The most trivial way to save data from Shiny is to simply save each response as its own file on the current server. To load the data, we simply load all the files in the output directory. In our specific example, we also want to concatenate all of the data files together into one data. frame.
To add an input in a Shiny app, we need to place an input function *Input() in the ui object. Each input function requires several arguments. The first two are inputId , an id necessary to access the input value, and label which is the text that appears next to the input in the app.
There is a stopApp
function that stops the running app and returns an optional value:
myValue <- runApp(list(
ui = bootstrapPage(
numericInput('n', 'Number of obs', 100),
actionButton("myBtn", "Press ME!"),
plotOutput('plot')
),
server = function(input, output, session) {
output$plot <- renderPlot({ hist(runif(input$n)) });
observe({
if(input$myBtn > 0){
stopApp(7)
}
})
}
))
On stopping:
> myValue
[1] 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With