View source: R/app_module_file.R
| ie_file_server | R Documentation |
The single source of truth for the isofiles in an isoexplorer app, and the hub
every other module talks to. It maintains a running set of read isofiles
(seeded from get_isofiles(), grown by uploads and watched folders), splits it
into the three measurement types (scans / continuous flow / dual inlet) with
isoreader2::ir_filter_for_scans() and friends, owns the shared intensity-units
selection and the per-type file selection, and exposes the per-type metadata
(for the ie_metadata_server() selector tables) and the selection-filtered
aggregated data (for the *_plot_server() modules).
ie_file_server(
id,
get_isofiles,
initial_selection = TRUE,
upload_folder = NULL,
monitoring_folders = NULL,
examples_folder = NULL,
temporary_storage = FALSE
)
ie_file_ui(id)
id |
the module id (namespace) |
get_isofiles |
a reactive returning an |
initial_selection |
what is selected, per type, before any selector pushes
a selection. An expression evaluated as a |
upload_folder |
directory where uploaded files are stored (created on
demand); |
monitoring_folders |
character vector of folders to watch; isofiles found
there with |
examples_folder |
directory the "Load examples" navbar button copies the
isoreader2 bundled example files into (and then loads). |
temporary_storage |
if |
Selector tables read get_<type>_metadata() and push their selection via
set_selected_<type>(); plot modules read get_aggregated_<type>_data() and
drive the shared units via get_units() / set_units().
Dynamic files. New files (uploaded, or appearing in monitoring_folders)
are read with isoreader2::ir_read_isofiles() and appended; aggregation is
incremental (only new files are read/aggregated, then combined with c()), so
already-read files are never re-read.
Upload. When upload_folder is set the module owns a navbar upload button
(the ie_file_ui() placeholder) that opens a modal to upload multiple files or
whole folders bundled as .zip archives (the picker allows .zip, the file
types isoreader2 reads, and .json – which covers their .<type>.json
serializations such as foo.cf.json). Uploaded files are stored in
upload_folder (archives unpacked), and only the just-uploaded files are
read – files already present in upload_folder when the app started are
left untouched. An "Auto-select the newly uploaded files" checkbox (off by
default) exclusively selects the new files in the relevant type's table and, in
the full multi-tab app, switches to that type's tab.
Monitoring. monitoring_folders are polled; any isofiles found there with
isoreader2::ir_find_isofiles() (including files already present at startup)
are read and added.
Getting started. When examples_folder and/or upload_folder is set but the
app is launched without data (empty get_isofiles()), a prompt is shown once
inviting the user to load the examples and/or upload their own files; an app
launched with data never sees it.
The "file handle": a list of reactive accessors / setters. For each
<type> in scans / cf / di: get_units()/set_units(units) (shared
intensity units, default "mV"); get_<type>_metadata();
set_selected_<type>(rows); get_<type>_selection();
get_aggregated_<type>_data(); plus get_<type>_select_signal() (file paths
a selector should select, fired by upload auto-select) and get_active_type()
(the type whose tab to activate after an auto-select).
ie_file_ui(): the navbar placeholders for the "Load examples" and
"Upload" buttons (each rendered only when the server's examples_folder /
upload_folder is set). Pair with ie_file_server() on the same id.
if (interactive()) {
library(shiny)
# read the bundled isoreader2 examples for some scans data
iso <-
isoreader2::ir_examples_folder() |>
isoreader2::ir_find_isofiles() |>
isoreader2::ir_read_isofiles()
ui <- bslib::page_fillable(
ie_type_explorer_ui("meta", ie_scans_plot_ui("scan"))
)
server <- function(input, output, session) {
# the hub: every other module reads/writes through this handle
file <- ie_file_server("files", get_isofiles = reactive(iso))
ie_scans_metadata_server("meta", file) # selection -> file server
ie_scans_plot_server("scan", file) # file server -> plot
}
shinyApp(ui, server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.