Time Series Analysis Blocks for blockr
Specialized time series functionality for blockr using tsbox and dygraphs. Provides comprehensive blocks for loading, transforming, and visualizing time series data as interactive dygraphs.
- π Interactive Dygraphs: All outputs render as interactive time series charts
- π¦ 25 Built-in Datasets: Easy access to R's time series datasets
- π Comprehensive Transformations: Changes, frequency conversion, lag/lead, scaling
- π Advanced Analysis: Forecasting, decomposition, PCA for multivariate series
- π¨ Professional UI: Consistent design following blockr.ggplot patterns
- π― tsbox Integration: Seamless format conversion and manipulation
# Install dependencies
install.packages(c("tsbox", "dygraphs", "forecast"))
# Install blockr.core if not already installed
# remotes::install_github("blockr-org/blockr.core")
# Install blockr.ts
devtools::install()
library(blockr.core)
library(blockr.ts)
# Create a pipeline using new_board()
blockr.core::serve(
new_board(
blocks = c(
data = new_ts_dataset_block(dataset = "AirPassengers"),
transform = new_ts_change_block(method = "pcy")
),
links = c(
data_to_transform = new_link("data", "transform")
)
)
)
Access all 25 built-in R time series datasets with an intuitive selector.
blockr.core::serve(
new_ts_dataset_block(dataset = "EuStockMarkets")
)
Calculate various types of changes: percentage, differences, year-over-year.
blockr.core::serve(
new_ts_change_block(method = "pcy"),
data = list(data = tsbox::ts_tbl(datasets::AirPassengers))
)
Methods:
pc
: Period-on-period percentage changepcy
: Year-on-year percentage changepca
: Annualized percentage changediff
: First differencesdiffy
: Year-on-year differences
Convert time series between temporal granularities with smart aggregation.
blockr.core::serve(
new_ts_frequency_block(to = "year", aggregate = "mean"),
data = list(data = tsbox::ts_tbl(datasets::AirPassengers))
)
Features:
- Automatic frequency detection
- Smart target selection (only allows aggregation)
- Multiple aggregation methods: mean, sum, first, last, min, max
Select specific series from multivariate time series data.
multivariate_data <- tsbox::ts_c(datasets::mdeaths, datasets::fdeaths)
blockr.core::serve(
new_ts_select_block(series = "mdeaths", multiple = FALSE),
data = list(data = tsbox::ts_tbl(multivariate_data))
)
Shift time series forward (lag) or backward (lead).
blockr.core::serve(
new_ts_lag_block(by = 12),
data = list(data = tsbox::ts_tbl(datasets::AirPassengers))
)
Filter time series to specific date ranges with an intuitive range slider.
blockr.core::serve(
new_ts_span_block(start = 1950, end = 1955),
data = list(data = tsbox::ts_tbl(datasets::AirPassengers))
)
Scale, normalize, or index time series for comparison.
blockr.core::serve(
new_ts_scale_block(method = "index"),
data = list(data = tsbox::ts_tbl(datasets::AirPassengers))
)
Methods:
normalize
: Scale to mean=0, sd=1index
: Index to base period (100)minmax
: Scale to [0, 1] range
Extract trend, seasonal, and remainder components.
blockr.core::serve(
new_ts_decompose_block(component = "seasonal_adjusted"),
data = list(data = tsbox::ts_tbl(datasets::AirPassengers))
)
Generate forecasts with confidence intervals.
blockr.core::serve(
new_ts_forecast_block(horizon = 24),
data = list(data = tsbox::ts_tbl(datasets::AirPassengers))
)
Principal Component Analysis for multivariate time series.
blockr.core::serve(
new_ts_pca_block(n_components = 2),
data = list(data = tsbox::ts_tbl(datasets::EuStockMarkets))
)
Convert time series data to regular data frame format, removing the dygraph visualization. Useful for integrating with non-TS blocks or exporting data.
blockr.core::serve(
new_ts_to_df_block(format = "long"),
data = list(data = tsbox::ts_tbl(tsbox::ts_c(datasets::mdeaths, datasets::fdeaths)))
)
blockr.core::serve(
new_ts_to_df_block(format = "wide"),
data = list(data = tsbox::ts_tbl(tsbox::ts_c(datasets::mdeaths, datasets::fdeaths)))
)
Convert wide-format data frames to time series format with dygraph visualization. Automatically detects time columns and converts numeric columns to separate series.
df_wide <- data.frame(
date = seq(as.Date("2020-01-01"), by = "month", length.out = 24),
sales = rnorm(24, 100, 10),
revenue = rnorm(24, 1000, 100),
costs = rnorm(24, 500, 50)
)
blockr.core::serve(
new_ts_from_df_block(),
data = list(data = df_wide)
)
For complex analyses with multiple branches, use the DAG board:
library(blockr.core)
library(blockr.ui)
library(blockr.dplyr)
library(blockr.ggplot)
library(blockr.ai)
# Create comprehensive analysis board
ts_board <- blockr.ui::new_dag_board(
blocks = c(
# Data sources
air = new_ts_dataset_block(dataset = "AirPassengers"),
stocks = new_ts_dataset_block(dataset = "EuStockMarkets"),
# AirPassengers branch
air_decomp = new_ts_decompose_block(component = "seasonal_adjusted"),
air_change = new_ts_change_block(method = "pcy"),
air_forecast = new_ts_forecast_block(horizon = 24),
# Stocks branch
stock_select = new_ts_select_block(series = c("DAX", "FTSE")),
stock_scale = new_ts_scale_block(method = "index"),
stock_pca = new_ts_pca_block(n_components = 2)
),
links = c(
# Connect AirPassengers pipeline
new_link("air", "air_decomp", "data"),
new_link("air_decomp", "air_change", "data"),
new_link("air_change", "air_forecast", "data"),
# Connect stocks pipeline
new_link("stocks", "stock_select", "data"),
new_link("stock_select", "stock_scale", "data"),
new_link("stock_scale", "stock_pca", "data")
)
)
# Serve the board
blockr.core::serve(ts_board)
- blockr.core - Core blockr framework
- blockr.ggplot - ggplot2 visualization blocks
- tsbox - Time series toolbox
- dygraphs - Interactive time series charts