-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
78 lines (60 loc) · 1.95 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Check if Package "ape" is installed otherwise install
is.installed <- function(checkinstall) is.element(checkinstall, installed.packages()[,1])
if (is.installed("ape"))
{
} else {
install.packages("ape")
}
# Set option to open app in browser window
options(shiny.launch.browser = T)
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
fluidRow(
column( width = 12,
fileInput("file1", "Load Tree File in Newick Format",
accept = c(
"text",
"tre",
"tree")),
tags$hr(),
fileInput("file2", "Load .csv Naming File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")),
checkboxInput("header", "Headers", TRUE),
tags$hr(),
selectInput("seperator", "Seperator", c(";",","), multiple = FALSE,
selectize = TRUE, width = "50px", size = NULL),
tags$hr(),
uiOutput("download")
)
)
)
server <- function(input, output) {
values <- reactiveValues()
observeEvent(input$file1,{
values$tree<- ape::read.tree(input$file1$datapath)
})
observeEvent(input$file2,{
values$names <- read.csv(input$file2$datapath, sep = input$seperator , header = input$header, stringsAsFactors = F)
values$names <- values$names[match(values$tree$tip.label, values$names[,1]),] #reorders name pair fail to order in tree
values$tree$tip.label <- values$names[,2] #replaces names in tree
})
output$download <- renderUI({
if(!is.null(input$file1) & !is.null(input$file2)) {
downloadButton("downloadData", "Download Renamed Tree")
}
})
output$downloadData <- downloadHandler(
filename = function() {
basename(input$file1$name)
},
content = function(file) {
ape::write.tree(values$tree, file)
}
)
}
shinyApp(ui, server)
}