Skip to content

Commit

Permalink
all buttons besides zip work
Browse files Browse the repository at this point in the history
  • Loading branch information
ncullen93 committed Mar 16, 2023
1 parent 8475a56 commit dadabfc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 66 deletions.
67 changes: 38 additions & 29 deletions components/board.loading/R/loading_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,8 @@ LoadingBoard <- function(id,
observeEvent(rl$selected_row, {
if (is.null(rl$selected_row)) {
shinyjs::disable(id = 'loadbutton')
shinyjs::disable(id = 'sharebutton')
shinyjs::disable(id = 'downloadpgx')
shinyjs::disable(id = 'downloadzip')
shinyjs::disable(id = 'deletebutton')
} else {
shinyjs::enable(id = 'loadbutton')
shinyjs::enable(id = 'sharebutton')
shinyjs::enable(id = 'downloadpgx')
shinyjs::enable(id = 'downloadzip')
shinyjs::enable(id = 'deletebutton')
}
}, ignoreNULL = FALSE)

Expand All @@ -74,7 +66,7 @@ LoadingBoard <- function(id,
observeEvent(
input$importbutton, {
selected_row <- rl$selected_row_shared
pgx_name <- rl$pgxTableShare_data[selected_row, 'dataset']
pgx_name <- rl$pgxTableShared_data[selected_row, 'dataset']

pgx_file <- file.path(pgx_shared_dir, paste0(pgx_name, '.pgx'))

Expand All @@ -94,8 +86,8 @@ LoadingBoard <- function(id,

# put user dataset into shared folder
observeEvent(
input$sharebutton, {
selected_row <- rl$selected_row
rl$share_pgx, {
selected_row <- as.numeric(stringr::str_split(rl$share_pgx, '_row_')[[1]][2])
pgx_name <- rl$pgxTable_data[selected_row, 'dataset']

alert_val <- shinyalert::shinyalert(
Expand Down Expand Up @@ -424,34 +416,51 @@ LoadingBoard <- function(id,
}
}

output$downloadpgx <- shiny::downloadHandler(
# DOWNLOAD PGX FILE #
observeEvent(rl$download_pgx, { shinyjs::click(id = 'download_pgx_btn') })
output$download_pgx_btn <- shiny::downloadHandler(
## filename = "userdata.pgx",
filename = function() {
selectedPGX()
sel <- row_idx <- as.numeric(stringr::str_split(rl$download_pgx, '_row_')[[1]][2])
df <- getFilteredPGXINFO()
pgxfile <- as.character(df$dataset[sel])
pgxfile <- paste0(sub("[.]pgx$", "", pgxfile), ".pgx")
pgxfile
},
content = function(file) {
pgxfile <- selectedPGX()
if (is.null(pgxfile) || pgxfile == "" || length(pgxfile) == 0) {
return(NULL)
}
sel <- row_idx <- as.numeric(stringr::str_split(rl$download_pgx, '_row_')[[1]][2])
df <- getFilteredPGXINFO()
pgxfile <- as.character(df$dataset[sel])
pgxfile <- paste0(sub("[.]pgx$", "", pgxfile), ".pgx")
pgx <- loadPGX(pgxfile)
temp <- tempfile()
save(pgx, file = temp)
file.copy(temp, file)
}
)

output$downloadzip <- shiny::downloadHandler(

# DOWNLOAD DATA AS ZIP FILE #
observeEvent(rl$download_zip, { shinyjs::click(id = 'download_zip_btn') })
output$download_zip_btn <- shiny::downloadHandler(
## filename = "userdata.zip",
filename = function() {
sub("pgx$", "zip", selectedPGX())
sel <- row_idx <- as.numeric(stringr::str_split(rl$download_zip, '_row_')[[1]][2])
df <- getFilteredPGXINFO()
pgxfile <- as.character(df$dataset[sel])
pgxfile <- paste0(sub("[.]pgx$", "", pgxfile), ".pgx")
pgxfile <- sub("pgx$", "zip", pgxfile)
print(pgxfile)
pgxfile
},
content = function(file) {
pgxfile <- selectedPGX()
if (is.null(pgxfile) || pgxfile == "" || length(pgxfile) == 0) {
return(NULL)
}
sel <- row_idx <- as.numeric(stringr::str_split(rl$download_zip, '_row_')[[1]][2])
print(paste('zip:',sel))
df <- getFilteredPGXINFO()
pgxfile <- as.character(df$dataset[sel])
pgxfile <- paste0(sub("[.]pgx$", "", pgxfile), ".pgx")
pgxname <- sub("[.]pgx$", "", pgxfile)
print(pgxname)
pgx <- loadPGX(pgxfile)
dir.create(tmp <- tempfile())
tmp2 <- file.path(tmp, pgxname)
Expand All @@ -477,15 +486,15 @@ LoadingBoard <- function(id,
}
)

shiny::observeEvent(input$deletebutton, {
pgxfile <- selectedPGX()
if (is.null(pgxfile) || pgxfile == "" || length(pgxfile) == 0) {
return(NULL)
}
shiny::observeEvent(rl$delete_pgx, {
row_idx <- as.numeric(stringr::str_split(rl$delete_pgx, '_row_')[[1]][2])

df <- getFilteredPGXINFO()
pgxfile <- as.character(df$dataset[row_idx])
pgxfile <- paste0(sub("[.]pgx$", "", pgxfile), ".pgx") ## add/replace .pgx

pgx.path <- getPGXDIR()
pgxfile1 <- file.path(pgx.path, pgxfile)
pgxfile1
sel <- NULL

deletePGX <- function() {
Expand Down
44 changes: 27 additions & 17 deletions components/board.loading/R/loading_table_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,40 @@ loading_table_datasets_server <- function(id,
for (i in 1:nrow(df)) {
new_menu <- actionMenu(
div(
style = "width: 175px;",
style = "width: 140px;",
div(
shiny::actionButton(
ns("deletebutton"),
label = "Delete Dataset", icon = icon("trash"),
class = "btn btn-outline-danger",
width = '100%',
style = 'border: none;'
),
shiny::downloadButton(
ns("downloadpgx"),
ns(paste0("download_pgx_row_",i)),
label = "Download PGX",
icon = NULL,
class = "btn btn-outline-dark",
style = "width: 100%; border: none;"
style = "width: 100%; border: none;",
onclick=paste0('Shiny.onInputChange(\"',ns("download_pgx"),'\",this.id)')
),
downloadButton2(
ns("downloadzip"),
label = "Download ZIP", icon = icon("file-archive"),
shiny::downloadButton(
ns(paste0("download_zip_row_", i)),
label = "Download ZIP",
icon = NULL,
class = "btn btn-outline-dark",
style = "width: 100%; border: none;"
style = "width: 100%; border: none;",
onclick=paste0('Shiny.onInputChange(\"',ns("download_zip"),'\",this.id)')
),
shiny::actionButton(
ns("sharebutton"),
label = "Share Dataset", icon = icon("share-nodes"),
ns(paste0("share_dataset_row_", i)),
label = "Share Dataset",
class = "btn btn-outline-info",
width = '100%',
style = 'border: none;'
style = 'border: none;',
onclick=paste0('Shiny.onInputChange(\"',ns("share_pgx"),'\",this.id)')
),
shiny::actionButton(
ns(paste0("delete_dataset_row_",i)),
label = "Delete Dataset",
class = "btn btn-outline-danger",
width = '100%',
style = 'border: none;',
onclick=paste0('Shiny.onInputChange(\"',ns("delete_pgx"),'\",this.id)')
)
)
),
size = "sm",
Expand All @@ -74,6 +80,10 @@ loading_table_datasets_server <- function(id,
)
menus <- c(menus, as.character(new_menu))
}
observeEvent(input$download_pgx, { rl$download_pgx <- input$download_pgx })
observeEvent(input$download_zip, { rl$download_zip <- input$download_zip })
observeEvent(input$share_pgx, { rl$share_pgx <- input$share_pgx })
observeEvent(input$delete_pgx, { rl$delete_pgx <- input$delete_pgx })

df$actions <- menus
colnames(df)[ncol(df)] <- ' '
Expand Down
34 changes: 14 additions & 20 deletions components/board.loading/R/loading_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,20 @@ LoadingUI <- function(id) {
),
div(
id = "load-action-buttons",
#shiny::actionButton(
# ns("deletebutton"),
# label = "Delete Dataset", icon = icon("trash"),
# class = "btn btn-outline-danger"
#),
#shiny::downloadButton(
# ns("downloadpgx"),
# label = "Download PGX",
# class = "btn btn-outline-dark"
#),
#downloadButton2(
# ns("downloadzip"),
# label = "Download ZIP", icon = icon("file-archive"),
# class = "btn btn-outline-dark"
#),
#shiny::actionButton(
# ns("sharebutton"),
# label = "Share Dataset", icon = icon("share-nodes"),
# class = "btn btn-outline-info"
#),
# this button is needed to trigger download but should be hidden
shiny::downloadLink(
ns("download_pgx_btn"),
label = "",
icon = NULL,
width = '0%'
),
# this button is needed to trigger download but should be hidden
shiny::downloadLink(
ns("download_zip_btn"),
label = "",
icon = NULL,
width = '0%'
),
shiny::actionButton(
ns("loadbutton"),
label = "Load Dataset", icon = icon("file-import"),
Expand Down

0 comments on commit dadabfc

Please sign in to comment.