rAmCharts-shinymodules-ts {rAmCharts}R Documentation

Shiny module to render large time-series data with live server-client aggregation

Description

Shiny module to render large time-series data with live server-client aggregation

Usage

rAmChartsTimeSeriesUI(id, width = "100%", height = "400px")

rAmChartsTimeSeriesServer(
  input,
  output,
  session,
  data,
  col_date,
  col_series,
  maxPoints = shiny::reactive(600),
  tz = shiny::reactive("UTC"),
  ts = shiny::reactive(c("5 min", "10 min", "30 min", "hour", "3 hour", "12 hour",
    "day", "week", "month", "year")),
  fun_aggr = shiny::reactive("mean"),
  treat_missing = shiny::reactive(FALSE),
  maxgap = shiny::reactive(Inf),
  type_aggr = shiny::reactive("first"),
  na.rm = shiny::reactive(TRUE),
  main = shiny::reactive(""),
  ylab = shiny::reactive(""),
  color = shiny::reactive(c("#2E2EFE", "#31B404", "#FF4000", "#AEB404")),
  type = shiny::reactive(c("line")),
  bullet = shiny::reactive(NULL),
  bulletSize = shiny::reactive(2),
  linetype = shiny::reactive(c(0, 5, 10, 15, 20)),
  linewidth = shiny::reactive(c(1, 1, 1, 1, 1, 1)),
  fillAlphas = shiny::reactive(0),
  precision = shiny::reactive(1),
  connect = shiny::reactive(FALSE),
  export = shiny::reactive(FALSE),
  legend = shiny::reactive(TRUE),
  legendPosition = shiny::reactive("bottom"),
  legendHidden = shiny::reactive(FALSE),
  ZoomButton = shiny::reactive(data.frame(Unit = "MAX", multiple = 1, label = "All")),
  ZoomButtonPosition = shiny::reactive("bottom"),
  periodFieldsSelection = shiny::reactive(FALSE),
  scrollbar = shiny::reactive(TRUE),
  scrollbarPosition = shiny::reactive("bottom"),
  scrollbarHeight = shiny::reactive(40),
  scrollbarGraph = shiny::reactive(NULL),
  cursor = shiny::reactive(TRUE),
  cursorValueBalloonsEnabled = shiny::reactive(TRUE),
  creditsPosition = shiny::reactive("top-right"),
  group = shiny::reactive(NULL),
  dataDateFormat = shiny::reactive("YYYY-MM-DD JJ:NN:ss"),
  categoryBalloonDateFormats = shiny::reactive(list(list(period = "YYYY", format =
    "YYYY"), list(period = "MM", format = "YYYY-MM"), list(period = "WW", format =
    "YYYY-MM-DD"), list(period = "DD", format = "YYYY-MM-DD"), list(period = "hh", format
    = "YYYY-MM-DD JJ:NN"), list(period = "mm", format = "YYYY-MM-DD JJ:NN"), list(period
    = "ss", format = "YYYY-MM-DD JJ:NN:ss"), list(period = "fff", format =
    "YYYY-MM-DD JJ:NN:ss"))),
  dateFormats = shiny::reactive(list(list(period = "YYYY", format = "YYYY"),
    list(period = "MM", format = "MMM"), list(period = "WW", format = "MMM DD"),
    list(period = "DD", format = "MMM DD"), list(period = "hh", format = "JJ:NN"),
    list(period = "mm", format = "JJ:NN"), list(period = "ss", format = "JJ:NN:ss"),
    list(period = "fff", format = "JJ:NN:ss"))),
  thousandsSeparator = shiny::reactive(" "),
  decimalSeparator = shiny::reactive("."),
  balloonFontSize = shiny::reactive(10),
  balloonMaxWidth = shiny::reactive(400)
)

Arguments

id

character, used to specify namesapce, see shiny::NS

width

character, the width of the chart container. For amChartsOutput.

height

character, the height of the chart container. For amChartsOutput.

input

standard, shiny input

output

standard, shiny output

session

standard, shiny session

data

: data.frame to transform.

col_date

Date column name, default to "date". Must be "POSIXct"

col_series

Column name of quantitative variable(s) to be transformed. Default to setdiff(colnames(data), "date")

maxPoints

: Maximal number of rows in results

tz

: Timezone of result. Defaut to "UTC".

ts

All enabled aggregation. Default to c("5 min", "10 min", "30 min", "hour", "3 hour", "12 hour", "day", "week", "month", "year"). Can be a number, in seconds, or a character string containing one of "min", "hour", "day".... This can optionally be preceded by a positive integer and a space

fun_aggr

: Aggregation function to use ("min", "max", "sum", "mean", "first", "last", "minabs", "maxabs"). Default to "mean".

treat_missing

: Boolean. Default to FALSE Whether or not to interpolate missing values ? see na.approx

maxgap

When interpolate missing values with na.approx. Maximum number of consecutive NAs to fill. Defaut to Inf.

type_aggr

character Type of aggregation

  • "first" : Date/Time result is equal to minimum of sequence, and this minimum is included in aggregation

  • "last" : Date/Time result is equal to maximum of sequence, and this maximum is included in aggregation

na.rm

: aggregation only. a logical value indicating whether NA values should be stripped before the computation proceeds.

main

character, title.

ylab

character, value axis label.

color

character, color of series (in hexadecimal).

type

character, Type of graph. Possible values are : "line" (default), "column", "step", "smoothedLine"

bullet

character, point shape. Possible values are : "diamond", "square", "bubble", "yError", "xError", "round", "triangleLeft", "triangleRight", "triangleUp"

bulletSize

numeric, size of bullet.

linetype

numeric, line type, 0 : solid, number : dashed length

linewidth

numeric, line width.

fillAlphas

numeric, fill. Between 0 (no fill) to 1.

precision

numeric, default set to 1.

connect

logical, default set to FALSE. Specifies whether to connect data points if data is missing.

export

logical, default set to FALSE. TRUE to display export feature.

legend

logical, enabled or not legend ? Defaut to TRUE.

legendPosition

character, legend position. Possible values are : "left", "right", "bottom", "top"

legendHidden

logical hide some series on rendering ? Defaut to FALSE

ZoomButton

data.frame, 3 or 4 columns :

  • "Unit" : Character. Times unit. 'ss', 'mm', 'hh', 'DD', 'MM', 'YYYY'

  • "multiple" : Numeric. multiple*unit

  • "label" : Character. button's label

  • "selected" : Boolean. Optional. To set initial selection. (One TRUE, others FALSE)

ZoomButtonPosition

character, zoom button position. Possible values are : "left", "right", "bottom", "top"

periodFieldsSelection

boolean, using zoom button, add also two fields to select period ?

scrollbar

boolean, enabled or not scrollbar ? Defaut to TRUE.

scrollbarPosition

character, scrollbar position. Possible values are : "left", "right", "bottom", "top"

scrollbarHeight

numeric, height of scroll bar. Default : 40.

scrollbarGraph

character, name of serie (column) to print in scrollbar. Defaut to NULL.

cursor

boolean, enabled or not cursor ? Defaut to TRUE.

cursorValueBalloonsEnabled

boolean, if cursor, enabled or not balloons on cursor ? Defaut to TRUE.

creditsPosition

character, credits position. Possible values are : "top-right", "top-left", "bottom-right", "bottom-left"

group

character, like in dygraphs, for synchronization in shiny or rmarkdown.

dataDateFormat

character Data date format. Default to 'YYYY-MM-DD JJ:NN:ss'. See amTimeSeries.

categoryBalloonDateFormats

list Date format objects for chart cursor. See amTimeSeries.

dateFormats

list Date format objects for x-axis. See amTimeSeries.

thousandsSeparator

character, default set to " "

decimalSeparator

character, default set to ".",

balloonFontSize

numeric, text font size on balloon. Default : 10.

balloonMaxWidth

numeric. Default : 400.

Value

a reactive expression with aggregate data and ts

Examples


## Not run: 

library(shiny)
library(rAmCharts)
library(data.table)

# number of points
n <- 1000000
data <- data.frame(date = seq(c(ISOdate(1999,12,31)), by = "5 min", length.out = n),
                          value = rnorm(n, 100, 50), check.names = FALSE)

# maximun of points in javascript
max_points <- 1000

# Call module in UI
ui <- fluidPage(
  rAmChartsTimeSeriesUI("ts_1", height = "600px"),
  h4(textOutput("ts"))
)

# Define server
server <- function(input, output) {
  
  # Call module in server
  res <- callModule(rAmChartsTimeSeriesServer, "ts_1", reactive(data), reactive("date"), 
     reactive("value"), maxPoints = shiny::reactive(max_points),
     main = reactive("Example of rAmChartsTimeSeries module"),
     color = reactive("red"), periodFieldsSelection = reactive(TRUE)
   )
   
  # show module return and print ts
  output$ts <- renderText({
    print(res())
    paste0("Current ts : ", res()$ts)
  })
 
}

# Run the application 
shinyApp(ui = ui, server = server)


## End(Not run)


[Package rAmCharts version 2.1.15 Index]