Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd basic `appshot.shiny.appobj` functionality #55
Conversation
|
Could not use library(shiny)
ui <- fluidPage(
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
plot(cars)
})
}
obj <- shinyApp(ui, server)
run_and_snapshot <- function(shinyAppObj) {
initialized <- FALSE
observe({
if (!initialized) {
invalidateLater(5000)
initialized <<- TRUE
return()
}
# Do whatever
message("Take snapshot")
shiny::stopApp()
})
print(obj)
message("Got here")
} |
|
@schloerke Can you elaborate on that? Calling system2 didn't ever return if you called it from where |
|
Updated to use |
| if (r_session$is_alive()) { | ||
| # try again later | ||
| shiny::invalidateLater(200) | ||
| } else { |
wch
Feb 23, 2018
Owner
It would also be good to have a timeout check, just in case the R process with webshot hangs for some reason.
It would also be good to have a timeout check, just in case the R process with webshot hangs for some reason.
| }, | ||
| args | ||
| ) | ||
|
|
wch
Feb 23, 2018
•
Owner
Maybe add on.exit(r_session$kill()) to make sure that it goes away? Although now that I think of it, that won't ensure that phantomjs process will exit -- in fact, it's probably the reverse, since if the child R process receives the hard kill signal, it won't be able to send any signals to the phantomjs process. Anyway, something should happen to ensure the child R process and grandchild phantomjs process exit.
Now that I think of it again, maybe killing the R process will cause the phantomjs process to exit. But the behavior might also be different on Windows.
Maybe add on.exit(r_session$kill()) to make sure that it goes away? Although now that I think of it, that won't ensure that phantomjs process will exit -- in fact, it's probably the reverse, since if the child R process receives the hard kill signal, it won't be able to send any signals to the phantomjs process. Anyway, something should happen to ensure the child R process and grandchild phantomjs process exit.
Now that I think of it again, maybe killing the R process will cause the phantomjs process to exit. But the behavior might also be different on Windows.
| r_session <- callr::r_bg( | ||
| function(...) { | ||
| # Wait for app to start | ||
| Sys.sleep(0.5) |
wch
Feb 27, 2018
Owner
This delay should be a parameter. Same for appshot.character.
This delay should be a parameter. Same for appshot.character.
schloerke
Feb 27, 2018
Author
Contributor
I think that is fair for us to keep it internal. It is a delay for webshot to start processing. The delay in taking the picture could be increased by the 'delay' parameter. By keeping it static at 0.5, it is a minimum of 0.5 seconds in processing before the webshot is taken.
I think that is fair for us to keep it internal. It is a delay for webshot to start processing. The delay in taking the picture could be increased by the 'delay' parameter. By keeping it static at 0.5, it is a minimum of 0.5 seconds in processing before the webshot is taken.
| @@ -40,14 +42,73 @@ appshot.character <- function(app, file = "webshot.png", ..., | |||
| p <- processx::process$new("R", args = c("--slave", "-e", cmd)) | |||
wch
Feb 27, 2018
Owner
Switch to callr::r_bg. We might not even need the processx package as a (direct) dependency.
Switch to callr::r_bg. We might not even need the processx package as a (direct) dependency.
| webshot_timeout <- webshot_timeout + 10 | ||
| } | ||
| webshot_timeout_ms <- webshot_timeout * 1000 | ||
| count <- 0 |
wch
Feb 27, 2018
Owner
Use times instead of counts.
Use times instead of counts.
| shiny::runApp(app, port = port, display.mode = "normal") | ||
|
|
||
| # return webshot::webshot file value | ||
| r_session$get_result() # safe to call as the r_session must have ended |
wch
Feb 27, 2018
Owner
Does this need to be invisible()?
Does this need to be invisible()?
|
@wch Added
|
Adds an appshot method for shiny app objects.