Skip to content

Commit

Permalink
Merge pull request #655 from bigomics/plot-unique-name
Browse files Browse the repository at this point in the history
recode: give plot/table output unique name using ns()
  • Loading branch information
mauromiguelm authored Aug 29, 2023
2 parents 66b081e + 3a92a93 commit 94adc29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
24 changes: 7 additions & 17 deletions components/ui/ui-PlotModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -399,19 +399,10 @@ PlotModuleServer <- function(id,
moduleServer(
id,
function(input, output, session) {
ns <- session$ns

filename <- ns("title")
stopwords <- c("-title", "-pltmod-title", "-plot-title", "-pltsrv-title", "-plotmodule-title")
x <- unlist(strsplit(filename, "-"))
x <- x[!x %in% stopwords]
filename <- paste(x, collapse = "-")

# replace empty spaces of title with underscore
filename <- gsub(" ", "_", filename)
# all caps down
filename <- tolower(filename)

ns <- session$ns
filename <- sub("-$","",ns('')) ## filename root

observeEvent(input$downloadOption,
{
if (!input$downloadOption %in% c("pdf", "png")) {
Expand Down Expand Up @@ -504,14 +495,13 @@ PlotModuleServer <- function(id,
do.png <- "png" %in% download.fmt
do.html <- "html" %in% download.fmt
do.obj <- "obj" %in% download.fmt

do.csv <- !is.null(csvFunc)

PNGFILE <- PDFFILE <- HTMLFILE <- CSVFILE <- NULL
if (do.pdf) PDFFILE <- paste0(gsub("file", filename, tempfile()), ".pdf")
if (do.png) PNGFILE <- paste0(gsub("file", filename, tempfile()), ".png")
if (do.csv) CSVFILE <- paste0(gsub("file", filename, tempfile()), ".csv")
HTMLFILE <- paste0(gsub("file", filename, tempfile()), ".html") ## tempory for webshot
if (do.pdf) PDFFILE <- paste0(gsub("file", "plot", tempfile()), ".pdf")
if (do.png) PNGFILE <- paste0(gsub("file", "plot", tempfile()), ".png")
if (do.csv) CSVFILE <- paste0(gsub("file", "data", tempfile()), ".csv")
HTMLFILE <- paste0(tempfile(), ".html") ## tempory for webshot
HTMLFILE
unlink(HTMLFILE)

Expand Down
15 changes: 3 additions & 12 deletions components/ui/ui-TableModule2.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,13 @@ TableModuleServer <- function(id,
height = c(640, 800),
width = c("auto", 1400),
selector = c("none", "single", "multi", "key")[1],
filename = "data.csv") {
filename = "table.csv") {
moduleServer(
id,
function(input, output, session) {
ns <- session$ns
filename <- ns("title")
# stopwords = ['-title', '-pltmod-title', '-plot-title', '-pltsrv-title', '-plotmodule-title']
# x <- unlist(strsplit(filename, "-"))
# x <- x[!x %in% stopwords]
# filename <- paste(x, collapse = "-")
# print(filename)
filename <- vapply(strsplit(filename, "-"), function(x) { # remove uninformative information.
paste(x[seq.int(2)], collapse = "-")
}, character(1L))
filename <- paste0(filename, ".csv")

filename <- paste0(sub(".csv$","",ns(filename)),".csv")

if (is.null(func2)) func2 <- func

# Downloader
Expand Down

0 comments on commit 94adc29

Please sign in to comment.