Skip to content

Commit

Permalink
Merge pull request #2 from jumpingrivers/main
Browse files Browse the repository at this point in the history
WP4: re-factor app
  • Loading branch information
oliviabboyd authored Nov 28, 2022
2 parents 3b653e9 + cb43ab0 commit ed73dc3
Show file tree
Hide file tree
Showing 443 changed files with 13,767 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
^tfpbrowser\.Rproj$
^\.Rproj\.user$
.lintr
^data-raw$
^\.github$
^LICENSE\.md$
_\.new\.png$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
29 changes: 29 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
30 changes: 30 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: lint

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
# {shinytest2}: Ignore new debug snapshots for `$expect_values()`
*_.new.png
12 changes: 12 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
linters: linters_with_defaults(
assignment_linter = NULL,
object_name_linter = NULL,
line_length_linter = line_length_linter(120),
undesirable_operator_linter = undesirable_operator_linter(
modify_defaults(
default_undesirable_operators,
"<-" = "Use =, not <-, for assignment."
)
)
)
exclusions: list("renv/")
36 changes: 36 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Package: tfpbrowser
Title: Builds Shiny application for 'tfpscanner' outputs
Version: 0.0.6
Authors@R:
person("Jumping", "Rivers", , "[email protected]", role = c("aut", "cre"))
Description: An R package to contain the code for the Shiny app to explore the
outputs from the 'tfpscanner' package.
License: MIT + file LICENSE
Depends:
R (>= 4.0.0)
Imports:
bslib,
dplyr,
fs,
ggplot2,
ggiraph,
glue,
htmltools,
janitor,
magrittr,
reactable,
readr,
rlang,
shiny,
shinyjs,
stringr,
tibble,
tidyr
Suggests:
shinytest2,
testthat,
usethis
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.2
LazyData: true
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2022
COPYRIGHT HOLDER: tfpbrowser authors
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2022 tfpbrowser authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(run_app)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(rlang,.env)
33 changes: 33 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# tfpbrowser 0.0.6 _2022-11-08_

- Switch to using rds inputs instead of html inputs
- Use {ggiraph} widget as input to folder selection
- Add functions to parse tooltip and extract cluster id
- Remove unnecessary html files

# tfpbrowser 0.0.5 _2022-11-02_

- Move panels from RHS to collapsible above
- Rearrange content of collapsible panel
- Add CSS file to style collapsible
- Remove mutation drop down for now

# tfpbrowser 0.0.4 _2022-10-19_

- Add module to download RDS files

# tfpbrowser 0.0.3 _2022-09-24_

- Split into modules

# tfpbrowser 0.0.2 _2022-09-06_

- add {shinytest2} tests

# tfpbrowser 0.0.1 _2022-09-05_

- initialise R package
- convert ui and server scripts to functions
- add data into package
- minor fixes to pass R CMD check

13 changes: 13 additions & 0 deletions R/add_ext_resources.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Add external resources to the shiny app
#'
#' Function is internally used to add external
#' resources inside the Shiny application.
add_ext_resources = function() {
shiny::addResourcePath(
"www", system.file("app/www", package = "tfpbrowser", mustWork = TRUE)
)
shiny::tags$head(
shinyjs::useShinyjs(),
shiny::tags$link(rel = "stylesheet", type = "text/css", href = "www/tfpbrowser-style.css")
)
}
76 changes: 76 additions & 0 deletions R/app_server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#' Shiny application server
#' @param input,output,session Internal parameters for `{shiny}`.
#' @noRd
app_server = function(input, output, session) {

# Load mutation selectize options on server-side
# (quicker loading on slower browsers)
# This is because there is a lot of options
# client-side processing is slow
shiny::updateSelectizeInput(session,
"mutations",
choices = get_unique_mutations(
system.file("app", "www", "data",
"sarscov2-audacity-westerncape2021.csv",
package = "tfpbrowser",
mustWork = TRUE)),
server = TRUE)



# Load treeview -----------------------------------------------------------

# create plotly output from saved ggplot2 outputs
output$treeview = ggiraph::renderGirafe({
filename = get_filename(input$widgetChoice)
g = readRDS(filename)
tooltip_css = paste0(
"background-color:black;",
"color:grey;",
"padding:14px;",
"border-radius:8px;",
"font-family:\"Courier New\",monospace;"
)
suppressWarnings(ggiraph::girafe(ggobj = g,
options = list(
ggiraph::opts_selection(
type = "single"),
ggiraph::opts_sizing(
width = 0.8),
ggiraph::opts_tooltip(
css = tooltip_css,
use_fill = FALSE)
)
))
})

# get selected cluster id based on widget choice
selected_cluster_id = shiny::reactive({
get_selected_cluster_id(widgetChoice = input$widgetChoice,
treeviewSelected = input$treeview_selected)
})

# output result of click
output$select_text = shiny::renderText({
paste("You have selected cluster ID:", selected_cluster_id())
})

# Tables Tab --------------------------------------------------------------
tablesServer(
"table1",
cluster_choice = selected_cluster_id
)

# Plots Tab ----------------------------------------------------------
plotsServer(
"plot1",
cluster_choice = selected_cluster_id
)

# RDS Tab ----------------------------------------------------------
rdsServer(
"rds1",
cluster_choice = selected_cluster_id
)

} # end server function
92 changes: 92 additions & 0 deletions R/app_ui.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#' Shiny application user interface
#'
#' @param request Internal parameter for `{shiny}`.
#' @noRd
app_ui = function(request) {
shiny::tagList(

shinyjs::useShinyjs(),

shiny::navbarPage(
# title
title = "tfpbrowser",

header = add_ext_resources(),
# theme
theme = bslib::bs_theme(version = 4,
bootswatch = "minty",
bg = "#EBEEEE",
fg = "#002147",
primary = "#003E74",
secondary = "#9D9D9D"),

# Input widgets
shiny::tabPanel(
title = "Data",

shiny::fluidRow(
shiny::column(12,
# use details and summary to create expandable section
htmltools::tags$details(
# preview of expandable section
htmltools::tags$summary("Download Files (click to expand)"),

shiny::br(),

# text to print choice
shiny::textOutput("select_text"),
shiny::br(),

# output options
shiny::tabsetPanel(id = "plot_tabs",

# Tables tab
tablesUI("table1"),

# Plots tab
plotsUI("plot1"),

# RDS tab
rdsUI("rds1")

)
)
)
), # end fluid row

# Bottom row - show tree (static html output from tfpscanner)
shiny::fluidRow(

shiny::column(12,

# choose type of treeviw
shiny::radioButtons(inputId = "widgetChoice",
label = "Select treeview",
choices = c(
"Logistic growth rate",
"Simple logistic growth rate",
"Simple trait log odds"),
inline = TRUE),

# show treeview widget
shiny::wellPanel(
ggiraph::girafeOutput("treeview"),
style = "background: white",
),
shiny::br()
)
) # end fluid row
), # end "data" page

# about page
shiny::tabPanel(
title = "About",
shiny::includeMarkdown(system.file("app", "www", "content", "about.md",
package = "tfpbrowser",
mustWork = TRUE))
)

) # end navbar page
) # end tag list

}
Loading

0 comments on commit ed73dc3

Please sign in to comment.