Using pipelines inside Shiny widgets or apps

library(analysisPipelines)
library(shiny)
knitr::opts_chunk$set(
    eval = FALSE
  )

Pipelines in shiny apps

Pipelines can be used as part of Shiny widgets or apps. In the following example, we define a simple pipeline which generates a chart, and use that to power a shiny widget.

In this example, we emulate streaming dataset using the shiny::reactivePoll function and randomly sampling from an existing sample dataset in the package.

  data("iris")
  shinyPipeline <- AnalysisPipeline()
  shinyPipeline %>>% setLoggerDetails(target = "none")
  shinyPipeline %>>% univarCatDistPlots(uniCol = "Species", priColor = "blue", optionalPlots = 0, storeOutput = T) ->   shinyPipeline

We then use the pipeline within the shiny::renderPlot function, and set the sampled data to execute the pipeline, and generate the chart. Since the data keeps changing due to our reactive poll, the expression within the shiny::renderPlot function keeps getting called in the reactive context.

  sampled_data <- shiny::reactivePoll(intervalMillis = 2000,
                                        session = NULL,
                                        checkFunc = function() return(base::sample(1:100, 1)),
                                        valueFunc = function() return(iris[sample(1:nrow(iris), 100),]))
  shiny::renderPlot(height = 400, {
      sampled_data <- sampled_data()
      shinyPipeline %>>% setInput(input = sampled_data) -> shinyPipeline
      shinyPipeline %>>% generateOutput %>>% getOutputById("1")
    })


Try the analysisPipelines package in your browser

Any scripts or data that you put into this service are public.

analysisPipelines documentation built on July 1, 2020, 7:09 p.m.