Skip to content

Commit

Permalink
prettified the reports during downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad1991 committed Dec 13, 2024
1 parent 347a03b commit 8cbb07e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
23 changes: 19 additions & 4 deletions bs/R/MainApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ app <- function() {

# Render results list
output$Results <- renderUI({
if (input$conditionedPanels == "DataWrangling" || input$conditionedPanels == "Dose Response analysis") {
if (input$conditionedPanels == "DataWrangling") {
return(
div(
class = "var-box-output",
Expand Down Expand Up @@ -543,15 +543,30 @@ app <- function() {
})

observeEvent(input$download, {
print_req(is_valid_filename(input$user_filename), "Defined filename is not valid")
if (!is_valid_filename(input$user_filename)) {
runjs("document.getElementById('user_filename').focus();")
print_noti(
why_filename_invalid(input$user_filename)
)
}
print_req(
is_valid_filename(input$user_filename),
"Defined filename is not valid"
)
print_req(length(listResults$all_data) > 0, "No results to save")
l <- listResults$all_data
if (Sys.getenv("RUN_MODE") == "SERVER") {
print_req(check_filename_for_server(input$user_filename), "Defined filename does not have xlsx as extension")
print_req(
check_filename_for_server(input$user_filename),
"Defined filename does not have xlsx as extension"
)
excelFile <- createExcelFile(l)
upload(session, excelFile, new_name = input$user_filename)
} else {
print_req(check_filename_for_serverless(input$user_filename), "Defined filename does not have zip as extension")
print_req(
check_filename_for_serverless(input$user_filename),
"Defined filename does not have zip as extension"
)
jsString <- createJSString(l)
session$sendCustomMessage(
type = "downloadZip",
Expand Down
31 changes: 31 additions & 0 deletions bs/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ print_req <- function(expr, message) {
req(expr)
}

# print notification without check
print_noti<- function(message) {
showNotification(message, type = "message")
}

# print success
print_success <- function(message) {
showNotification(message)
Expand Down Expand Up @@ -515,6 +520,32 @@ is_valid_filename <- function(filename) {
})
}

why_filename_invalid <- function(filename) {
try({
if (!is.character(filename)) {
return("Filename has to consist of characters")
}
if (grepl(" ", filename)) {
return("Found spaces in filename")
}
invalid_chars <- "[<>:\"/\\|?*]"
if (grepl(invalid_chars, filename)) {
return("Found invalid chars in filename: [<>:\"\\|?*")
}
if (nchar(filename) == 0) {
return("Filename is empty")
}
if (nchar(filename) >= 100) {
return("Filename is too long (> 100 characters)")
}
ex <- strsplit(basename(filename), split = "\\.")[[1]]
if (length(ex) == 1) { # no extension found
return("Filename extension is missing")
}
return("")
})
}

check_filename_for_server <- function(filename) {
ex <- strsplit(basename(filename), split = "\\.")[[1]]
ex <- ex[[length(ex)]]
Expand Down

0 comments on commit 8cbb07e

Please sign in to comment.