Skip to content

Commit

Permalink
Merge pull request #3 from TileDB-Inc/aw/callr-backend
Browse files Browse the repository at this point in the history
Migrate backend to callr
  • Loading branch information
aaronwolen authored Jun 9, 2021
2 parents f82f110 + 03d6e3d commit 12f99fd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tiledbJupyterShiny
Type: Package
Title: Render Shiny apps inside a Jupyter notebook
Version: 0.1.1.9001
Version: 0.1.2
Author: TileDB
Maintainer: TileDB <[email protected]>
Description: Render Shiny apps inside a Jupyter notebook.
Expand All @@ -11,6 +11,7 @@ LazyData: true
Imports:
IRdisplay,
shiny,
future
callr,
pingr
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN mamba install -c conda-forge --quiet --yes \
'bash_kernel' \
'r-shiny' \
'r-irkernel' \
'r-future' \
'r-pingr' \
&& mamba clean --all -f -y

# install the tiledbJupyterShiny package
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(renderShinyApp)
import(future)
import(shiny)
importFrom(IRdisplay,display_html)
importFrom(callr,r_bg)
importFrom(pingr,is_up)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# tiledbJupyterShiny 0.1.2

* Added a `NEWS.md` file to track changes to the package.
* Apps are now launched as background tasks using the *callr* package.
* We now verify an app is up and running before rendering the IFrame
28 changes: 20 additions & 8 deletions R/renderShinyApp.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#' Render Shiny Application in a Jupyter Notebook
#'
#' @param ui The UI definition of the app.
#' @param port The TCP port that the application should listen on (defaults to 3000).
#' @inheritParams shiny::shinyApp
#' @importFrom IRdisplay display_html
#' @import shiny
#' @import future
#' @importFrom callr r_bg
#' @importFrom pingr is_up
#' @export

renderShinyApp <- function(
ui = NULL,
server = NULL,
appFile = NULL,
appDir = NULL
appDir = NULL,
port = 3000
) {
port <- 3000

if (!is.null(ui) || !is.null(server)) {
app <- shiny::shinyApp(ui, server)
} else if (!is.null(appFile)) {
Expand All @@ -28,11 +29,22 @@ renderShinyApp <- function(
)
}

plan(multisession)
future::future(runApp(app, host = "0.0.0.0", port = port))
run_app <- function(appDir, host, port) {
shiny::runApp(appDir, host = host, port = port)
}
args <- list(appDir = app, host = "0.0.0.0", port = port)

rproc <- callr::r_bg(
func = run_app,
args = args,
supervise = TRUE
)

Sys.sleep(1)
displayIframe(port)
while(!pingr::is_up(destination = args$host, port = args$port)) {
if (!rproc$is_alive()) stop(rproc$read_all_error())
Sys.sleep(0.05)
}
displayIframe(port = args$port)
}


Expand Down
10 changes: 9 additions & 1 deletion man/renderShinyApp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12f99fd

Please sign in to comment.