Skip to content

Commit

Permalink
News 2025.01.03-1
Browse files Browse the repository at this point in the history
  • Loading branch information
lgschuck committed Jan 3, 2025
1 parent e46fc02 commit 0b9c3a0
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 37 deletions.
32 changes: 32 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ editor_options:

## TO DO

1 - use reactive instead of reactiveValues for datasets

## 2025.01.03-1

### Bug Fixes

1 - Data Overview - after Edit only refresh if updat in rows or sample: fixed with insertion of buttons inside output$pD_over_gt. Avaliate use of reactive instead of reactiveValues for datasets.

### Improvements

1 - **export_file_module**: separator order now semicolon as default

2 - new **import_file_module**: allows input csv and RDS files

3 - **page_config_module**: new visual and size of input file as parameter

4 - **spada function**:

* sidebar now with Dataset Info accordion open by default

* small visual changes (icons and capital in some titles)

* **shiny.maxRequestSize** set to 500 MB by default

* **datasets_names_react**: now names of the datasets are a reactive (used several times)

* new **buttons in sidebar** accordion to navigate through pages

* new **buttons in active dataset popover** navigate through pages

### Bug Fixes

## 2025.01.02-1

### Bug Fixes
Expand Down
8 changes: 4 additions & 4 deletions R/export_file_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ export_file_ui <- function(id) {
checkboxInput(ns('x_rownames'), 'Save row names'),
fluidRow(
column(3, radioButtons(ns('radio_separator'), 'Separator',
c('Comma' = ',', 'Semicolon' = ';'), inline = T)),
column(3, radioButtons(ns('radio_decimal'), 'Decimal Mark',
c('Semicolon' = ';', 'Comma' = ','), inline = T)),
column(3, radioButtons(ns('radio_decimal'), 'Decimal mark',
c('Dot' = '.', 'Comma' = ','), inline = T))
),
fluidRow(
column(3, textInput(ns('txt_na'), 'Missing (NA) substitute', value = '')),
column(3, radioButtons(ns('radio_scientific'), 'Scientific Notation',
column(3, radioButtons(ns('radio_scientific'), 'Scientific notation',
c('No' = 999999999, 'Allow' = 0), inline = T))
)
)
)
),
card_footer(downloadButton(ns('down_handler'),
'Export Active Dataset', icon('download')))
'Export Active dataset', icon('download')))
)
)
}
Expand Down
125 changes: 125 additions & 0 deletions R/import_file_module.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

# ui --------------------------------------------------------------------------
import_file_ui <- function(id) {
file_extensions <- c('csv', 'RDS')
ns <- NS(id)
card(
card_body(
fluidRow(
column(3, textInput(ns('dataset_name'), 'Dataset name', 'dataset')),
column(3, radioButtons(ns('radio_file_ext'), 'File format',
file_extensions, inline = T)),
column(3, fileInput(ns('file'), 'Choose a File')),
),
conditionalPanel(
condition = sprintf("input['%s'] == 'csv'", ns('radio_file_ext')),
card(
card_header('Csv Parameters', class = 'mini-header'),
card_body(
layout_column_wrap(
checkboxInput(ns('x_csv_header'), 'Header', T),
radioButtons(ns('radio_separator'), 'Separator',
c('Semicolon' = ';', 'Comma' = ','), inline = T),
radioButtons(ns('radio_decimal'), 'Decimal Mark',
c('Dot' = '.', 'Comma' = ','), inline = T),
btn_task(ns('btn_preview_raw'), 'Preview raw file', icon('magnifying-glass')),
),
)
)
),
),
card_footer(
btn_task(ns('btn_import'), 'Import file', icon('upload')),
)
)
}

# server ----------------------------------------------------------------------
import_file_server <- function(id, current_names) {
moduleServer(id, function(input, output, session) {

data <- reactiveValues(data = NULL, data_name = NULL)

observe({
if(is.null(input$file)){
msg_error('Insert a file')
} else if(!is_valid_name(input$dataset_name) || input$dataset_name %in% current_names){
msg_error('Name invalid or already in use')
} else {
file <- input$file
ext <- tools::file_ext(file$datapath)

if (ext == 'csv' && input$radio_file_ext == 'csv') {

tryCatch(
{ data$data <- fread(
file = file$datapath,
sep = input$radio_separator,
dec = input$radio_decimal,
check.names = T,
nrows = Inf,
skip = 0,
header = input$x_csv_header)

data$data_name <- input$dataset_name

msg('File imported')
},
warning = \(w) msg_error('Check parameters'),
error = \(e) msg_error('Check parameters')
)

} else if (ext == 'RDS' && input$radio_file_ext == 'RDS') {

data_temp <- readRDS(file$datapath)

if(data_temp |> is.data.frame()){
data$data <- data_temp
data$data_name <- input$dataset_name

msg('File imported')
} else {
msg_error('Object must be data.frame')
}
} else {
msg_error(paste('Insert a', input$radio_file_ext, 'file'))
}
}

}) |> bindEvent(input$btn_import)

observe({
req(input$file)

file <- input$file
ext <- tools::file_ext(file$datapath)

if (ext == 'csv' && input$radio_file_ext == 'csv') {
preview_data <- readLines(file$datapath, n = 8)

showModal(modalDialog(
size = 'xl',
title = 'Preview Raw File',
HTML(paste(preview_data, collapse = '<br>'))
))

} else {
msg_error(paste('Insert a', input$radio_file_ext, 'file'))
}
}) |> bindEvent(input$btn_preview_raw)

data_imported <- reactive({
req(data$data)
req(data$data_name)
req(input$dataset_name)
list('data' = data$data,
'data_name' = data$data_name,
# return the click integer for update the value outside the module
# even if the name and file was used before
'btn_click' = input$btn_import)
})

return(list(data_imported = data_imported))

})
}
23 changes: 16 additions & 7 deletions R/page_config_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ page_config_ui <- function(id) {
value = 'config',
title = 'Config',
icon = bs_icon('sliders2'),
card(style = 'background-color: #02517d;', card(
card_body(
h2('Config'),
card(style = 'background-color: #02517d;', layout_columns(
col_widths = c(9, 3), card(card_body(
h4('Colors'),
selectInput(
ns('sel_palette'),
'Select colors for plots',
Expand All @@ -18,12 +18,15 @@ page_config_ui <- function(id) {
'Palette 3' = 3
)
),
fluidRow(column(3, plotOutput(
ns('sample_plot')
)))
)
plotOutput(ns('sample_plot'))
)), card(card_body(
h4('Size input files'),
numericInput(ns('input_file_size'), 'Size in MB', 500, min = 0, step = 100),
btn_task(ns('btn_file_size'), 'Apply', icon('check'))
))
))
)

}

# server ----------------------------------------------------------------------
Expand Down Expand Up @@ -58,6 +61,12 @@ page_config_server <- function(id) {

}) |> bindCache(palette())

observe({
options(shiny.maxRequestSize = input$input_file_size * 1024 ^ 2)
msg('New limit applied')

}) |> bindEvent(input$btn_file_size)

return(list(palette = palette))
})
}
Loading

0 comments on commit 0b9c3a0

Please sign in to comment.