-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.R
74 lines (60 loc) · 2.03 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
library("shiny")
library("ape")
library("rotl")
# Define UI
ui <- fluidPage(
titlePanel("Open Tree Extractor"),
fileInput('target_upload', 'Choose csv file to upload',
accept = c(
'text/csv',
'text/comma-separated-values',
'.csv'
)),
tags$hr(),
checkboxInput("header", "Header", TRUE),
radioButtons("separator","Separator: ",choices = c(",", ";", ":"), selected=",", inline=TRUE),
mainPanel(
tabsetPanel(
tabPanel("Table", dataTableOutput("table"), downloadButton("DownloadTable", "Download Table")),
tabPanel("Tree_Plot", plotOutput("plot"), downloadButton("DownloadTree", "Download Tree"))
)
)
)
# Define server logic
server <- shinyServer(function(input, output) {
output$table <- renderDataTable({
inFile <- input$target_upload
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath,
header = input$header,
sep = input$separator, stringsAsFactors=FALSE, quote="")
names(df) <- c("Common_Name", "Scientific_Name")
species <- tnrs_match_names(names = df$Scientific_Name)
species
})
#Tree plot
output$plot <-renderPlot({
inFile <- input$target_upload
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath,
header = input$header,
sep = input$separator, stringsAsFactors=FALSE, quote="")
names(df) <- c("Common_Name", "Scientific_Name")
species <- tnrs_match_names(names = df$Scientific_Name)
tree <- tol_induced_subtree(ott_ids=species$ott_id, label_format = "name")
plot.phylo(tree)
})
# Downloadable selected file ----
output$downloadData <- downloadHandler(
filename = function() {
paste("Request_subset_OTL_", Sys.Date(), ".tre", sep = "")
},
content = function(file) {
write.tree(tree, file)
}
)
})
# Run the application
shinyApp(ui = ui, server = server)