Type: Package
Title: File Sharing Shiny Module
Version: 0.1.5
Description: Shiny module for easily sharing files between users. Admin can add, remove, edit and download file. User can only download file. It's also possible to manage files using R functions directly.
License: GPL-3
Encoding: UTF-8
RoxygenNote: 7.3.3
Imports: htmltools, shiny, tools, yaml, DT, R.utils, knitr, zip
Suggests: testthat
NeedsCompilation: no
Packaged: 2025-12-05 10:24:21 UTC; BenoîtThieurmel
Author: Benoit Thieurmel [aut, cre], Thibaut Dubois [aut], Jérémy Boussaguet [ctb]
Maintainer: Benoit Thieurmel <bthieurmel@gmail.com>
Repository: CRAN
Date/Publication: 2025-12-06 11:30:02 UTC

Add / suppress / edit a file

Description

Add / suppress / edit a file

Usage

add_file_in_dir(
  file,
  dir,
  yml,
  name = tools::file_path_sans_ext(basename(file)),
  description = "",
  date_time_format = "%Y%m%d_%H%M%S"
)

edit_file_in_dir(
  id,
  dir,
  yml,
  name = NULL,
  description = NULL,
  file = NULL,
  date_time_format = "%Y%m%d_%H%M%S"
)

suppress_file_in_dir(id, dir, yml)

get_yaml_info(
  yml,
  recorded_name = TRUE,
  date_time_format = "%Y%m%d_%H%M%S",
  add_img = FALSE,
  img_size = 30,
  format_size = TRUE
)

Arguments

file

character file (to copy) path.

dir

character directory path.

yml

character yaml configuration file full path.

name

character file name.

description

character file description.

date_time_format

character DateTime format.

id

character file id in yaml.

recorded_name

logical : add recorded name (with date_time extension) in output ?

add_img

logical : Use in shiny module for adding file extension img.

img_size

integer : Use in shiny module for adding file extension img.

format_size

logical : User-friendly size format ?

Value

These functions return a logical indicating if operation succeeded or not

Examples

## Not run: 

yml <- file.path(getwd(), "test_sfm/config.yml") # will be created

dir <- file.path(getwd(), "test_sfm")
dir.create(dir)

file <- system.file("translate/translate.csv", package = "shinydrive")

# add one first file with current name
add_file_in_dir(
  file = file,
  dir = dir,
  yml = yml,
  description = ""
)

yaml::yaml.load_file(yml)
list.files(dir)
get_yaml_info(yml)

# add same file twice, changing name
add_file_in_dir(
  file = file,
  dir = dir,
  yml = yml,
  name = "translate_2",
  description = "This is cool"
)

yaml::yaml.load_file(yml)
list.files(dir)
get_yaml_info(yml, recorded_name = F)

# modify first file
edit_file_in_dir(
  id = "2", 
  dir = dir, 
  yml = yml,
  name = "translate_2_mod",
  description = "So cool"
)

yaml::yaml.load_file(yml)
list.files(dir)

# suppress first file
suppress_file_in_dir(id = "1", dir = dir, yml = yml)

yaml::yaml.load_file(yml)
list.files(dir)


## End(Not run)


Combine YAML files recursively from subdirectories

Description

Combine YAML files recursively from subdirectories

Usage

combine_yaml_recursive(
  base_dir,
  current_dir = "",
  config_file = "files_desc.yaml",
  recorded_name = TRUE,
  date_time_format = "%Y%m%d_%H%M%S",
  add_img = FALSE,
  img_size = 30,
  format_size = TRUE
)

Arguments

base_dir

Base directory path

current_dir

Current directory relative to base_dir (use "" for base_dir itself)

config_file

YAML configuration file name

recorded_name

Add recorded name (with date_time extension) in output?

date_time_format

DateTime format

add_img

Use in shiny module for adding file extension img

img_size

Use in shiny module for adding file extension img

format_size

User-friendly size format?

Value

A data frame combining all YAML files with a 'subdir' column indicating relative path

Examples

## Not run: 
# Get all files from base_dir and subdirectories
all_files <- combine_yaml_recursive(
  base_dir = "~/my_files",
  current_dir = "",
  config_file = "files_desc.yaml"
)

# Get files from a specific subdirectory and its children
subdir_files <- combine_yaml_recursive(
  base_dir = "~/my_files",
  current_dir = "projects/2024",
  config_file = "files_desc.yaml"
)

## End(Not run)

Delete all YAML files

Description

Delete all YAML files

Usage

delete_config(
  base_dir,
  config_file = "files_desc.yaml",
  confirm = TRUE,
  dry_run = FALSE,
  verbose = TRUE
)

Arguments

base_dir

Folder to check for YAML files

config_file

YAML files names

confirm

With or without confirmation before deleting

dry_run

simulation (no deletion)

verbose

Display messages

Value

delete all yaml files

Examples

## Not run: 
\donttest{
delete_config("~/shinydrive/tests", config_file = "files_desc.yaml")
}

## End(Not run)

Delete config files older than a specific number of days

Description

Delete config files older than a specific number of days

Usage

delete_old_config(
  base_dir,
  days = 30,
  config_file = "files_desc.yaml",
  confirm = TRUE,
  dry_run = FALSE,
  verbose = TRUE
)

Arguments

base_dir

base folder

days

number of days to check the age of files we want to delete

config_file

name of YAML files

confirm

With or without confirmation before deleting

dry_run

Simulation

verbose

Display messages

Value

delete old config files from folder

Examples

delete_old_config("~/shinydrive/tests", days = 60, config_file = "files_desc.yaml")


Create YAML configuration files recursively

Description

Create YAML configuration files recursively

Usage

init_config(
  base_dir,
  config_file = "files_desc.yaml",
  file_patterns = NULL,
  verbose = TRUE
)

Arguments

base_dir

Base directory path

config_file

YAML configuration file name

file_patterns

File patterns to match

verbose

Display messages

Value

Invisible count of processed directories


File management shiny module.

Description

File management shiny module.

Usage

shiny_drive_ui(id)

shiny_drive_server(
  input,
  output,
  session,
  id,
  save_dir,
  dir_access = NULL,
  admin_user = TRUE,
  force_desc = FALSE,
  lan = "EN",
  file_translate = read.csv(system.file("translate/translate.csv", package =
    "shinydrive"), sep = ";", encoding = "UTF-8", check.names = FALSE),
  datatable_options = list(),
  yml = "files_desc.yaml",
  date_time_format = "%Y%m%d_%H%M%S",
  decreasing = TRUE,
  intervalMillis = 5000
)

Arguments

id

character. An ID string

input

shiny input

output

shiny input

session

shiny input

save_dir

character/reactive. Main directory of the files.

dir_access

character/reactive vector for dir(s) access. Default to NULL (all directories)

admin_user

boolean/reactive (TRUE). Admin user or not.

force_desc

boolean/reactive (FALSE). Force to add an entry description ?

lan

character/reactive ("EN"). Language to be used in the module (FR, EN and CN availabled... contributions are welcome :)).

file_translate

data.frame/reactive File for translation.

datatable_options

list/reactive. DT::datatable options argument.

yml

characte/reactiver yaml configuration file name.

date_time_format

character DateTime format.

decreasing

logical Order table output on date.

intervalMillis

integer. In case of "reactive" time betweens calls looking of files changes

Value

Shiny module without return value.

Examples

## Not run: 

if(require(shiny)){
  ui <- fluidPage(
    shiny_drive_ui(id = "idm")
  )
  server <- function(input, output, session) {
    callModule(module = shiny_drive_server,
             id = "idm",
             session = session,
             admin_user = TRUE,
             save_dir =  getwd(),
             lan = "FR")
  }
  shinyApp(ui, server)
}


## End(Not run)