Skip to content

Commit

Permalink
Adding tooltips in Shiny
Browse files Browse the repository at this point in the history
  • Loading branch information
Michelle Kendall committed Oct 30, 2015
1 parent 0c7cf49 commit 6aa4698
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: treescape
Title: Statistical Exploration of Landscapes of Phylogenetic Trees
Version: 1.8.13
Version: 1.8.14
Authors@R: c(TJ=person("Thibaut", "Jombart", email="[email protected]", role = c("aut")),
MK=person("Michelle", "Kendall", email="[email protected]", role = c("aut", "cre")),
JAG=person("Jacob", "Almagro-Garcia", role = c("aut")),
Expand Down
9 changes: 9 additions & 0 deletions R/servers.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
#' @author Thibaut Jombart \email{thibautjombart@@gmail.com}
#' @author Michelle Kendall \email{michelle.louise.kendall@@gmail.com}
#'
#' @import ape

#' @import shiny
#' @importFrom ade4 dudi.pco
#' @importFrom adephylo distTips
#' @importFrom adegraphics s.class
#' @importFrom adegraphics s.label
#' @importFrom adegraphics s1d.barchart
#' @importFrom phangorn Children
#' @importFrom phangorn Descendants
#' @importFrom utils packageDescription
#' @importFrom RLumShiny jscolorInput
#'
#'
#' @export
treescapeServer <- function(){
## RUN APP
Expand Down
26 changes: 22 additions & 4 deletions inst/shiny/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ shinyServer(function(input, output, session) {
if(!require("adegenet")) stop("adegenet is required")
if(!require("phangorn")) stop("phangorn is required")
if(!require("shinyRGL")) stop("shinyRGL is required")
if(!require("shinyBS")) stop("shinyBS is required")

# suppress warning messages from creating temporary directories when 3d plotting
suppressWarnings(warning("dir.create(dir)"))
Expand Down Expand Up @@ -54,7 +55,14 @@ shinyServer(function(input, output, session) {
}
else input$dataset
})

getSampleSize <- reactive({
input$sampleSize
})

getRandSamp <- reactive({
input$randSamp
})
## GET DATA ##
getData <- reactive({
out <- NULL
Expand Down Expand Up @@ -87,15 +95,25 @@ shinyServer(function(input, output, session) {
out <- read.nexus(file=newName)
}

l <- length(out)

## fix potential bug with input of two trees
validate(
need(length(out)>2, "treescape expects at least three trees. The function treeDist is suitable for comparing two trees.")
need(l>2, "treescape expects at least three trees. The function treeDist is suitable for comparing two trees.")
)

# get a manageable number of trees by sampling if necessary
randSamp <- getRandSamp()
if(randSamp == TRUE){
sampleSize <- getSampleSize()
if (l>sampleSize) {
updateSliderInput(session, "sampleSize", "Size of random sample:", value=sampleSize, min=10, max=l, step=10)
out <- out[sample(1:l,sampleSize)]
}
else{ # could only happen initially if <=10 trees supplied
updateSliderInput(session, "sampleSize", "Size of random sample:", value=l, min=3, max=l, step=1)
}

## warn of potential problems with input of too many / large trees
if(length(out)*length(out[[1]]$tip.label)>=500) {
warning("You have supplied many and/or large trees, so Shiny is likely to be slow. If no output appears soon, consider supplying fewer trees or comparing them using the standard R functions in treescape.")
}

## fix potential bug with tip labels - they need to match
Expand Down
27 changes: 22 additions & 5 deletions inst/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ shinyUI(
strong("accepted formats:"), br(),
em("- multiphylo"), "saved from R (.RData/.rda)", br(),
em("- nexus"), "file (.nex/.nexus)")
),
checkboxInput("randSamp","Randomly sample from the trees?", value=TRUE),
bsTooltip("randSamp", "For large sets of trees and/or trees with many tips the app may be slow, so beginning the analysis with a small random sample is recommended.",
placement = "right", trigger = "hover", options = NULL),
conditionalPanel(
condition="input.randSamp",
sliderInput("sampleSize", "Size of random sample:", value=10, min=10, max=300, step=10)
)
),


## ANALYSIS
img(src="img/line.png", width="100%"),
h2(HTML('<font color="#6C6CC4" size="6"> > Analysis </font>')),
h4(HTML('<font color="#6C6CC4" size="6"> > Analysis </font>')),

## choose metric
selectInput("treemethod", "Choose a tree summary:",
Expand All @@ -65,18 +72,21 @@ shinyUI(

## lambda, axes
uiOutput("lambda"),
bsTooltip("lambda","When lambda=0 trees are compared topologically; increasing lambda gives more focus to branch lengths"),

conditionalPanel(
condition="input.plotType==1",
uiOutput("naxes")

## Future: highlight median trees (if plotType==1)
#checkboxInput("showMedians", label=strong("Highlight median tree(s)?"), value=FALSE)
),


## find clusters?
checkboxInput("findGroves", label=strong("Identify clusters?"), value=FALSE),

bsTooltip("findGroves","Statistical tools for choosing an appropriate clustering method and number of clusters will be added to treescape soon.", placement="right"),


conditionalPanel(
## condition
Expand All @@ -92,14 +102,15 @@ shinyUI(

## number of clusters
uiOutput("nclust")
),
),

## relevant if method = KC metric, allow tip emphasis
conditionalPanel(
condition="input.treemethod=='metric'",
## Emphasise tips
checkboxInput("emphTips", label=strong("Emphasise tips?"), value=FALSE),
## if tip emphasis is chosen, provide options:
bsTooltip("emphTips","Choose tips to emphasise or de-emphasise: the vector elements corresponding to these tips are multiplied by the weight chosen below.", placement="right"),
## if tip emphasis is chosen, provide options:
conditionalPanel(
condition="input.emphTips",

Expand All @@ -118,6 +129,7 @@ shinyUI(
radioButtons("plotType", "View",
choices=c("Full tree landscape"=1,"Distances from a reference tree"=2),
selected=1),
bsTooltip("plotType", "Choose whether to view the relative distances between all trees, or a 1-dimensional plot of their distances from a fixed reference tree"),

## Dimensions (3D possible if 3 or more axes retained, and full tree landscape)
conditionalPanel(condition="input.naxes>2",
Expand All @@ -137,7 +149,8 @@ shinyUI(

## select second axis to plot
numericInput("yax", "Indicate the y axis", value=2, min=1, max=3),

bsTooltip("yax", "If multiple MDS axes have been retained, any combination of axes can be viewed"),

## if in 3D, need a z axis:
conditionalPanel(condition="input.plot3D==3",
numericInput("zax", "Indicate the z axis", value=3, min=1, max=3)
Expand Down Expand Up @@ -294,6 +307,7 @@ shinyUI(
radioButtons("treeChoice", "Tree selection",
choices=c("Median tree"="med","General tree selection"="gen"),
selected="med", width="100%"),
bsTooltip("treeChoice", "A geometric median tree is plotted by default. If clusters have been identified, the median for each can be viewed. Alternatively, any individual tree can be plotted."),

conditionalPanel(condition = "input.treeChoice=='med'",
selectInput("selectedMedTree", "Median tree from:",
Expand Down Expand Up @@ -403,6 +417,9 @@ shinyUI(
choices=c("Choose one"="","All trees"="all"), width="100%"),
#h2(HTML('<font color="#6C6CC4" size="2"> Note: this can be slow for large sets of trees </font>')),

bsTooltip("selectedDensiTree", "View all trees together in a densiTree plot. If clusters have been identified, the set of trees from a single cluster can be plotted. Note this function can be slow if many trees are included.", placement="bottom"),


## DENSITREE AESTHETICS
img(src="img/line.png", width="100%"),
h2(HTML('<font color="#6C6CC4" size="6"> > Aesthetics </font>')),
Expand Down

0 comments on commit 6aa4698

Please sign in to comment.