Shiny

Theres two recommended way in which we can run shiny apps in nextjournal. One way is to call the shinyApp function with a ui object and a server function as arguments:

library(shiny)
ui <- basicPage(
  plotOutput("plot1", click = "plot_click"),
  verbatimTextOutput("info")
)
server <- function(input, output) {
  output$plot1 <- renderPlot({
    plot(mtcars$wt, mtcars$mpg)
  })
  output$info <- renderText({
    paste0("x=", input$plot_click$x, "\ny=", input$plot_click$y)
  })
}
shinyApp(ui, server)
1.6s
shinyAppShinyApp (R)
R+future

On the other hand we can call shinyAppDir function against a folder containing shiny applicatino files

This repo is mounted by: ShinyAppDir
ls /shiny-examples
0.9s
ShinyAppDir (Bash in R)
R+future
library(shiny)
shinyAppDir('/shiny-examples/050-kmeans-example')
1.2s
ShinyAppDir (R)
R+future

Environment

In order to run shiny apps we need to add the future package to the host environment in order to run shiny server on a separate process and not block the whole notebook.

install.packages('future')
12.6s
R+future (R)

Runtimes (3)