rm(list = ls())
library(datasets)
library(data.table)
library(ggplot2)

runWithoutInstall <- T
ifelse(runWithoutInstall,
       sapply(list.files(path = "../R/", pattern="*R", full.names = T), source),
       library(shinypipe))

n <- 42
r.data <- reactive(
  data.table(int = as.integer(runif(n) * 100 + 1), 
             dbl = runif(n),
             date = Sys.Date() + 1:n,
             time = Sys.time() + (1:n)^2 * 60))

Sidebar {.sidebar}

renderUI({
  cols <- names(r.data())
  colsY <- list(choices = cols)
  colsX <- list(choices = c(cols[-1], cols[1]))
  ui.formula("form", colsY, colsX, simpleFormula = T, theme = "small")
})
r.form <- callModule(s.formula, "form")

Brush

Row 1

User controls zoom mode; Modify plot; Zoom direction control

r.yVal <- callModule(s.formula.y, "form")
r.xVal <- callModule(s.formula.x, "form")

r.plot <- reactive(geom_point(aes_string(x=r.xVal(), y=r.yVal())))

ui.plot("plot.modify")
r.brushedData.modify <- callModule(s.plot, "plot.modify", r.plot.modify, r.data)

Selected Data in the left plot (or full data if nothing is selected)

renderDataTable({
  tt <- r.brushedData.modify()
  if (nrow(tt) == 0) return (r.data())
  tt
})

Row 2

Brush to select

r.plot.modify <- reactive(list(
  r.plot(),
  theme_classic(base_size = 20)))

ui.plot("plot", zoom=NULL, brush=list(direction="x"))
r.brushedData <- callModule(s.plot, "plot", r.plot, r.data)

Shows brushed region from the left

ui.plot("plot.sec", zoom=T)
r.brushedData.sec <- callModule(s.plot, "plot.sec", r.plot, r.brushedData)

Debug

ui.flexOutput("flex-non-edit")
invisible(callModule(s.flexOutput, "flex-non-edit", environment(), "ls()", editable=F))

ui.flexOutput("flex")
invisible(callModule(s.flexOutput, "flex", environment(), "r.data()", "Table", rows=5))


rajkar86/shinypipe documentation built on Aug. 22, 2021, 9:48 p.m.