Generic file exporter module
The Generic File Exporter Module offers a flexible and versatile solution for saving diverse types of files within a Shiny application.
Unlike the specialized Plot Exporter Module, which focuses specifically on plot exporting and includes options for resizing and format selection, this module is designed to handle a broad range of file types and formats, catering to diverse file-saving needs.
UI function
The UI function for this module creates a button within the Shiny app interface. Clicking this button initiates the file-saving process. This interface is minimalistic, providing a straightforward means for users to trigger file-saving operations.
UI function call
mod_save_file_generic_ui("file_exporter_1")
Server function
The server function of the Generic File Exporter Module is responsible for executing the file-saving logic. When the user clicks the save button, this function performs necessary checks and executes a user-defined file-saving function with specified parameters.
The flexibility of this module allows you to define your own file-saving functions and parameters, providing greater control over the file-saving process.
Parameters
Description | Name |
---|---|
A unique identifier for the module instance. | id |
A reactive values list that must include the following fields: FUN - The function used to create the file (e.g., write.table, save, write_json, write_xml, SaveH5Seurat...). args - A list of arguments for the provided function. filename: The name of the file to be saved. extension: The expected file extension for proper validation. overwrite: Boolean indicating if the file with the same name should be overwritten. | reac_vals |
Path to the mounted /sbgenomics directory, which contains project-files, output-files, and workspace sub-directories. This directory structure should mirror the Platform file system for proper integration. | sbg_directory_path |
You as a developer are responsible for defining these parameters and integrating them with the module. You can also add additional UI components, such as file name inputs or format selectors, and use their values to populate the parameters provided to the server function.
Note:
- For testing locally, you can create a mock sbgenomics directory with the required structure.
- Users receive clear alerts regarding the success or failure of the file-saving process, ensuring they are informed of any issues or confirmations.
Server function call
mod_save_file_generic_server(
id = "file_exporter_1",
reac_vals = list(
FUN = write.table,
args = list(x = my_data_frame, file = "my_file.csv"),
filename = "my_file",
extension = "csv",
overwrite = TRUE
),
sbg_directory_path = "/sbgenomics")
Integration
To integrate the Generic File Exporter Module into your Shiny application, follow these steps:
- Add the UI Function: Insert
mod_save_file_generic_ui("file_exporter_1")
in the UI section of your app where you want the save button to appear. - Add the Server Function: Include
mod_save_file_generic_server("file_exporter_1", reac_vals, sbg_directory_path)
in the server section of your app. Ensurethat reac_vals
is a properly defined reactive values list.
To see the generic file exporter module in use, refer to the demo app available at: inst/demos/generic_file_exporter_demo_app.R.
Please note that the generic file picker module only adds basic action button to the Shiny app interface. You are responsible for defining additional UI elements, such as filename text inputs, separator selection elements, file extension dropdowns, etc. These elements should be integrated with the module and their values used to configure the parameters passed to the server function.
Updated about 2 months ago