Title: Interactive File Import and Export Blocks
Version: 0.1.0
Description: Extends 'blockr.core' with interactive blocks for reading and writing data files. Supports CSV, Excel, Parquet, RDS, and other formats through a graphical interface without writing code directly. Includes file browser integration and configurable import/export options.
URL: https://bristolmyerssquibb.github.io/blockr.io/
BugReports: https://github.com/BristolMyersSquibb/blockr.io/issues
License: GPL (≥ 3)
Depends: R (≥ 4.1.0)
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.3
VignetteBuilder: knitr
Imports: blockr.core (≥ 0.1.1), readxl, shiny, readr, shinyFiles, rio, arrow, bslib, rappdirs, shinyjs, writexl, zip
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
Config/testthat/parallel: true
NeedsCompilation: no
Packaged: 2025-12-21 14:00:27 UTC; christophsax
Author: Christoph Sax ORCID iD [aut, cre], Nicolas Bennett [aut], David Granjon [aut], Mike Page [aut], Bristol Myers Squibb [fnd]
Maintainer: Christoph Sax <christoph@cynkra.com>
Repository: CRAN
Date/Publication: 2026-01-07 08:00:08 UTC

blockr.io: Interactive File Import and Export Blocks

Description

Extends 'blockr.core' with interactive blocks for reading and writing data files. Supports CSV, Excel, Parquet, RDS, and other formats through a graphical interface without writing code directly. Includes file browser integration and configurable import/export options.

Author(s)

Maintainer: Christoph Sax christoph@cynkra.com (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Get blockr option with fallback

Description

Get blockr option with fallback

Usage

blockr_option(name, default = NULL)

CSS Utilities for blockr.io Blocks

Description

This file provides centralized CSS functions for consistent block styling. All custom classes use the ⁠.block-⁠ prefix to distinguish them from framework classes (Bootstrap, Shiny, etc.) and prevent naming conflicts.

Details

Required for all blocks:

Common optional utilities:

Usage in block UI:

ui = function(id) {
  tagList(
    css_responsive_grid(),        # Always include first
    css_single_column("myblock"), # If single column layout needed
    css_inline_checkbox(),        # If using inline checkboxes
    # ... block-specific CSS with tags$style(HTML(...)) ...
    # ... block HTML structure ...
  )
}

Block-specific styling (unique to one block) should use tags$style(HTML(...)) directly in the block file, not added here. Only add CSS here if it's reused by 2+ blocks.


Detect file category for UI adaptation

Description

Categorizes files by extension into broad categories that determine which UI options to show (csv/excel/arrow/other).

Usage

detect_file_category(path)

Arguments

path

Character. File path.

Value

Character. One of: "csv", "excel", "arrow", "other"


Extract names for variadic block arguments

Description

Helper function for variadic blocks. Processes ...args names to handle numeric indices vs named arguments.

Usage

dot_args_names(x)

Arguments

x

List with names (typically ...args)

Value

Character vector of names, or NULL if all numeric


Download URL to temporary file

Description

Downloads a file from a URL to a temporary location. Extracts file extension from URL if available to help with format detection.

Usage

download_url_to_temp(url)

Arguments

url

Character. URL to download from.

Value

Path to temporary file containing downloaded data.


Generate filename for write operations

Description

Generate filename for write operations

Usage

generate_filename(filename = "", timestamp = Sys.time())

Arguments

filename

Character. User-specified filename (without extension). If empty or NULL, generates timestamped filename.

timestamp

POSIXct timestamp for auto-generated names. Default: Sys.time()

Value

Character. Base filename without extension


Get list of file extensions supported by rio

Description

Returns a comprehensive list of file formats that can be handled by rio::import(). Used for file browser accept parameter and format validation.

Usage

get_rio_extensions()

Value

Character vector of file extensions (without dots)


Check if object is a single string

Description

Check if object is a single string

Usage

is_string(x)

Validate URL format

Description

Validate URL format

Usage

is_valid_url(url)

Unified file reading block

Description

A single block for reading files in various formats with smart UI that adapts based on detected file type. Supports "From Browser" (upload) and "From Server" (browse) modes with persistent storage for uploaded files.

Usage

new_read_block(
  path = character(),
  source = "upload",
  combine = "auto",
  args = list(),
  ...
)

Arguments

path

Character vector of file paths to pre-load. When provided, automatically switches to "path" mode regardless of the source parameter.

source

Either "upload" for file upload widget, "path" for file browser, or "url" for URL download. Default: "upload". Automatically set based on path parameter.

combine

Strategy for combining multiple files: "auto", "rbind", "cbind", "first"

args

Named list of format-specific reading parameters. Only specify values that differ from defaults. Available parameters:

  • For CSV files: sep (default: ","), quote (default: '"'), encoding (default: "UTF-8"), skip (default: 0), n_max (default: Inf), col_names (default: TRUE)

  • For Excel files: sheet (default: NULL), range (default: NULL), skip (default: 0), n_max (default: Inf), col_names (default: TRUE)

...

Forwarded to blockr.core::new_data_block()

Details

File Handling Modes

The block supports three modes:

From Browser mode (upload):

From Server mode (path):

URL mode:

Smart Adaptive UI

After file selection, the UI detects file type and shows relevant options:

Multi-file Support

When multiple files are selected:

Value

A blockr data block that reads file(s) and returns a data.frame.

Configuration

The following settings are retrieved from options and not stored in block state:

Examples

# Create a read block for a CSV file
csv_file <- tempfile(fileext = ".csv")
write.csv(mtcars[1:5, ], csv_file, row.names = FALSE)
block <- new_read_block(path = csv_file)
block

# With custom CSV parameters
block <- new_read_block(
  path = csv_file,
  args = list(n_max = 3)
)

if (interactive()) {
  # Launch interactive app
  serve(new_read_block())
}


Unified file writing block

Description

A variadic block for writing dataframes to files in various formats. Accepts multiple input dataframes and handles single files, multi-sheet Excel, or ZIP archives depending on format and number of inputs.

Usage

new_write_block(
  directory = "",
  filename = "",
  format = "csv",
  mode = "download",
  auto_write = FALSE,
  args = list(),
  ...
)

Arguments

directory

Character. Default directory for file output (browse mode only). Can be configured via options(blockr.write_dir = "/path") or environment variable BLOCKR_WRITE_DIR. Default: tempdir().

filename

Character. Optional fixed filename (without extension).

  • If provided: Writes to same file path on every upstream change (auto-overwrite)

  • If empty (default): Generates timestamped filename (e.g., data_20250127_143022.csv)

format

Character. Output format: "csv", "excel", "parquet", or "feather". Default: "csv"

mode

Character. Either "download" for "To Browser" (triggers browser download), or "browse" for "To Server" (writes to server filesystem). Default: "download"

auto_write

Logical. When TRUE, automatically writes files when data changes (browse mode only). When FALSE (default), user must click "Submit" button to save. Has no effect in download mode.

args

Named list of format-specific writing parameters. Only specify values that differ from defaults. Available parameters:

  • For CSV files: sep (default: ","), quote (default: TRUE), na (default: "")

  • For Excel/Arrow: Minimal options needed (handled by underlying packages)

...

Forwarded to blockr.core::new_transform_block()

Details

Variadic Inputs

This block accepts multiple dataframe inputs (1 or more) similar to bind_rows_block. Inputs can be numbered ("1", "2", "3") or named ("sales_data", "inventory"). Input names are used for sheet names (Excel) or filenames (multi-file ZIP).

File Output Behavior

Single input:

Multiple inputs + Excel:

Multiple inputs + CSV/Arrow:

Filename Behavior

Fixed filename (filename = "output"):

Auto-timestamped (filename = ""):

Mode: To Browser vs To Server

To Browser mode (download):

To Server mode (browse):

Value

A blockr transform block that writes dataframes to files

Examples

# Create a write block for CSV output
block <- new_write_block(
  directory = tempdir(),
  filename = "output",
  format = "csv"
)
block

# Write block for Excel with auto-timestamp
block <- new_write_block(
  directory = tempdir(),
  filename = "",
  format = "excel"
)

if (interactive()) {
  # Launch interactive app
  serve(new_write_block())
}


Create Arrow file reading expression

Description

Create Arrow file reading expression

Usage

read_expr_arrow(path, ...)

Arguments

path

Character. File path

...

Reading parameters (currently unused)

Value

Expression calling arrow::read_parquet, arrow::read_feather, or arrow::read_ipc_file


Create CSV/TSV/delimited file reading expression

Description

Create CSV/TSV/delimited file reading expression

Usage

read_expr_csv(path, ...)

Arguments

path

Character. File path

...

Reading parameters: sep, col_names, skip, n_max, quote, encoding

Value

Expression calling readr::read_csv, readr::read_tsv, or readr::read_delim


Create Excel file reading expression

Description

Create Excel file reading expression

Usage

read_expr_excel(path, ...)

Arguments

path

Character. File path

...

Reading parameters: sheet, range, col_names, skip, n_max

Value

Expression calling readxl::read_excel


Create rio import expression

Description

Create rio import expression

Usage

read_expr_rio(path, ...)

Arguments

path

Character. File path

...

Reading parameters (currently unused)

Value

Expression calling rio::import


Create expression for a single file

Description

Create expression for a single file

Usage

read_expr_single(path, file_type, ...)

Arguments

path

Character. Single file path

file_type

Character. Type of file

...

Parameters for the reader function

Value

A language object (expression)


Set names helper (base R doesn't export this in older versions)

Description

Set names helper (base R doesn't export this in older versions)

Usage

set_names(x, nm)

Build expression to write data to Arrow format (Parquet or Feather)

Description

Build expression to write data to Arrow format (Parquet or Feather)

Usage

write_expr_arrow(data_names, path, format = "parquet")

Arguments

data_names

Character vector of data object names to write

path

Character. Full file path for output

format

Character. Either "parquet" or "feather"

Value

A language object (expression) that writes Arrow file(s)


Build expression to write data to CSV file(s)

Description

Build expression to write data to CSV file(s)

Usage

write_expr_csv(data_names, path, args = list())

Arguments

data_names

Character vector of data object names to write

path

Character. Full file path for output

args

List of write parameters (sep, quote, na, etc.)

Value

A language object (expression) that writes CSV file(s)


Build expression to write data to Excel file with multiple sheets

Description

Build expression to write data to Excel file with multiple sheets

Usage

write_expr_excel(data_names, path)

Arguments

data_names

Named character vector where names are sheet names

path

Character. Full file path for output

Value

A language object (expression) that writes Excel file