Skip to content

Commit

Permalink
Add the shiny app into the package
Browse files Browse the repository at this point in the history
  • Loading branch information
aursiber committed May 22, 2020
1 parent 00623fe commit 0f000e6
Show file tree
Hide file tree
Showing 13 changed files with 7,034 additions and 12 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Version: 1.0-1
Author: Aurélie Siberchicot, Delphine Charif, Gabriel Terraz and Fabrice Vavre
Maintainer: Aurélie Siberchicot <[email protected]>
Imports: RColorBrewer
Suggests: DT, shiny, shinyBS
License: GPL (>=2.0)
LazyData: yes
Encoding: UTF-8
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ library(Mondrian)
```



# The shiny app

A web application (a `Shiny` application) is available to use the functionalities of the `Mondrian` package in an interactive way.
In this application, two examples are shown. The user can also upload its own data and compute the `mondrian` function on it.
The display output can then be saved.

The `MONDRIAN Shiny app` can be found at:
http://lbbe-shiny.univ-lyon1.fr/MondrianShiny/
`MondrianShiny` can be run on a R session, doing:
```r
shiny::runApp(system.file("MondrianShiny", package = "Mondrian"))
```

or online at:
<a href="http://lbbe-shiny.univ-lyon1.fr/MondrianShiny/" target="_blank">http://lbbe-shiny.univ-lyon1.fr/MondrianShiny/</a>

This shiny app is runing with the development version of `Mondrian`.



Expand Down
4 changes: 4 additions & 0 deletions inst/MondrianShiny/global.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(shinyBS)
library(Mondrian)
library(DT)
library(tools)
4 changes: 4 additions & 0 deletions inst/MondrianShiny/rinstall.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
install.packages("shinyBS",dependencies = TRUE, repos = "http://cran.univ-lyon1.fr")
install.packages("DT",dependencies = TRUE, repos = "http://cran.univ-lyon1.fr")
install.packages("RColorBrewer", dependencies = TRUE, repos = "http://cran.univ-lyon1.fr")
install.packages("Mondrian", dependencies = TRUE, repos = "http://cran.univ-lyon1.fr")
201 changes: 201 additions & 0 deletions inst/MondrianShiny/server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
shinyServer(function(input, output) {

##########################################
############### runex1 ###################
##########################################
output$ex1plot <- renderPlot({
data(endosymbiont_1pop)
mondrian(endosymbiont_1pop, col = c("blue", "red", "yellow"))
})

output$ex1table <- renderPrint({
data(endosymbiont_1pop)
pdf("temp1.pdf")
res <- mondrian(endosymbiont_1pop, col = c("blue", "red", "yellow"))
dev.off()
if(file.exists("temp1.pdf"))
file.remove("temp1.pdf")
return(res)
})

output$ex1data <- renderDataTable({
data(endosymbiont_1pop)
DT::datatable(endosymbiont_1pop, options = list(pageLength = 10, searching = FALSE))
})



##########################################
############### runex2 ###################
##########################################

output$ex2plot <- renderPlot({
data(endosymbiont_3pop)
mondrian(endosymbiont_3pop, pop = 1)
})

output$ex2table <- renderPrint({
data(endosymbiont_3pop)
pdf("temp2.pdf")
res <- mondrian(endosymbiont_3pop, pop = 1)
dev.off()
if(file.exists("temp2.pdf"))
file.remove("temp2.pdf")
return(res)
})

output$ex2data <- renderDataTable({
data(endosymbiont_3pop)
DT::datatable(endosymbiont_3pop, options = list(pageLength = 10, searching = FALSE))
})


##########################################
############## runmyplot #################
##########################################
loaddata <- reactive({
input$doplot
isolate({

inFile <- input$file
if (! is.null(inFile)) {

## data import
dd <- read.table(inFile$datapath, header = TRUE)
# TODO message d'erreur s'il n'y a pas les bonnes colonnes dans le fichier d'entrée
xx <- input$xlab
yy <- input$ylab
indiv <- input$indiv

if (input$pop == "multipop") {
mm <- ""
pp <- input$numpop

## labels
ll <- NULL
## colors
if (input$colors == "")
cc <- NULL
else
cc <- rep(strsplit(input$colors, " ")[[1]], length.out = NCOL(dd) - 1)


} else {
pp <- NULL
mm <- input$main

## labels
if (input$labels == "")
ll <- colnames(dd)
else
ll <- rep(strsplit(input$labels, " ")[[1]], length.out = NCOL(dd))

## colors
if (input$colors == "")
cc <- NULL
else
cc <- rep(strsplit(input$colors, " ")[[1]], length.out = NCOL(dd))
}

return(list(dd = dd, ll = ll, cc = cc, pp = pp, xx = xx, yy = yy, mm = mm, indiv = indiv))
}
})
})


plotdata <- reactive({
res <- loaddata()
isolate({
if(is.null(res$pp) & ("pop" %in% names(res$dd))) {
return("Your dataset contains a 'pop' column indicating that your dataset comes from several sub-populations. You must indicate in which column the sub-population factor is in your dataset.")
} else if (!is.null(res$pp) & !("pop" %in% names(res$dd))) {
return("Your dataset don't contain a 'pop' column indicating that your dataset comes from a unique sub-population. You must indicate that your dataset come from 'only one population'.")
} else {
mm <- mondrian(res$dd, labels = res$ll, xlab = res$xx, ylab = res$yy, main = res$mm, col = res$cc, pop = res$pp, indiv = res$indiv)
return(mm)
}
})
})


validateFile <- function(){
inFile <- input$file
extFile <- file_ext(inFile$name)
validate(
need(extFile == "txt" | extFile == "csv", "Only .txt or .csv files are allowed.")
)
}


output$mondrianplot <- renderPlot({
input$doplot
isolate({
inFile <- input$file
if (! is.null(inFile)) {
validateFile()
plotdata()
}
})
})


output$mondriantable <- renderPrint({
input$doplot
isolate({
inFile <- input$file
if (! is.null(inFile)) {
validateFile()
pdf("tempmondrian.pdf")
res <- plotdata()
dev.off()
if(file.exists("tempmondrian.pdf"))
file.remove("tempmondrian.pdf")
if (! is.null(res))
return(res)
}
})
})

output$mondriandata <- renderDataTable({
input$doplot
isolate({
inFile <- input$file
if (! is.null(inFile)) {
validateFile()
res <- as.data.frame(loaddata()$dd)
res <- res[complete.cases(res), ]
DT::datatable(res, options = list(pageLength = 10, searching = FALSE))
}
})
})







plotdata2 <- function() {
res <- loaddata()
mondrian(res$dd, labels = res$ll, xlab = res$xx, ylab = res$yy, main = res$mm, col = res$cc, pop = res$pp, indiv = res$indiv)
}

output$save <- downloadHandler(
filename = function() {
paste("mondrian_", Sys.Date(), ".png", sep = "")
},

content = function(file) {
png(file)
plotdata2()
dev.off()
},
contentType = 'image/png'
)

# outputOptions(output, "save", suspendWhenHidden = FALSE)




})
Loading

0 comments on commit 0f000e6

Please sign in to comment.