Shiny

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')

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)

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

ls /shiny-examples
library(shiny)
shinyAppDir('/shiny-examples/050-kmeans-example')