library(shiny)
library(plotly)
library(DT)
library(loxcoder)
library(shinydashboard)
library(rlist)
library(shinyFiles)
library(shinyalert)
library(knitr)
library(rmarkdown)
library(yaml)
library(gridExtra)
library(testit)
library(shinyjs)
### INITIALIZE
load_origin_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
load_pair_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
#NN167_small = readRDS(file = "Loxcode_experiments/NN167_small.rds")
#NN156_small = readRDS(file = "Loxcode_experiments/NN156_small.rds")
#NN156 = readRDS(file = "Loxcode_experiments/NN156.rds")
#NN167 = readRDS(file = "Loxcode_experiments/NN167.rds")
#col = readRDS(file = "Loxcode_experiments/col.rds")
# lox <- as(NN167_small,"loxcode_experiment")
# attr(lox,"alias")=list()
# attr(lox,"order")=list()
# lox=fill_alias(lox);
#lox <- col
exp = list(lox)
d <- summary_table(lox, "all_samples")
### CONSTANTS
chart_choices = c("Statistics Plots", "Heatmap", "Saturation Plot", "Pair Comparison Plot")
header <- dashboardHeader(
title = "LoxCodeR",
dropdownMenuOutput("curr_lox")
)
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Import", tabName="import", icon=icon("upload")),
menuItem(
"Create", tabName="create", icon=icon("folder-plus"),
menuSubItem("Create Code Sets", tabName="codeset-create"),
menuSubItem("Create Sample Sets", tabName="sample-create"),
menuSubItem("Filter Codes", tabName="codes-filter")
),
menuItem(
"Plots", tabName="plots", icon=icon("chart-bar"),
menuSubItem("Statistics Plots", tabName="stats-plot"),
menuSubItem("Heat Map", tabName="heatmap-plot"),
menuSubItem("Saturation Plot", "saturation-plot"),
menuSubItem("Pair Comparison Plot", "pair-plot")
),
menuItem("Report", tabName="report", icon=icon("file-alt")),
menuItem("Log", tabName="log", icon=icon("history"))
)
)
body <- dashboardBody(
tabItems(
tabItem(
tabName = "import",
box(
width = 6,
title = "Method 1: Upload a loxcode experiment object",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
fileInput("rds_file", "Choose an rds file:", multiple=TRUE, accept=c("rds")),
actionButton("submit_rds", "Upload")
),
box(
width = 6,
title = "Method 2: Upload samplesheet and fastq directory",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
textInput("name_exp", "Name of the loxcode experiment:", placeholder="Experiment Name"),
fileInput("samplesheet", "Choose an xlsx file of samples", multiple=FALSE, accept=c("xlsx")),
textInput("dir_input", "Choose a fastq directory"),
actionButton("submit_fastq", "Upload")
),
box(
width = 12,
title = "Loxcode Experiments",
status = "danger",
colour = NULL,
solidHeader = FALSE,
collapsible = FALSE,
dataTableOutput("experiments_table"),
actionButton("select_exp", "Select"),
actionButton("merge_exp", "Merge selected"),
actionButton("del_exp", "Delete"),
downloadButton("save_exp", "Download Current")
),
box(
width = 12,
title = "Sample Sheet",
status = "danger",
collapsible = TRUE,
collapsed = TRUE,
dataTableOutput("samplesheet")
)
),
tabItem(
tabName = "codeset-create",
fluidRow(
box(
title = "View a code set",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("view_codeset", label="Choose code set:", choices=names(lox@code_sets)),
actionButton("delete_codeset", "Delete Code Set")
),
box(
title = "Edit code sets",
status = NULL,
color = "red",
solidHeader = TRUE,
collapsible = TRUE,
textInput("name_codeset", label="Name of new codeset:", placeholder="Code Set Name"),
fluidRow(
column(4, actionButton("create_codeset", "Create from Selection")),
column(4, actionButton("create_all_codeset", "Create from All")),
column(4, actionButton("rename_codeset", "Rename Current"))
)
),
box(
width = 12,
title = "Code Set Table",
status = "danger",
solidHeader = FALSE,
wellPanel(dataTableOutput("codeset_table")),
verbatimTextOutput("selected_codes")
)
)
),
tabItem(
tabName = "sample-create",
fluidRow(
box(
width = 6,
title = "View a sample set",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("view_sample", label="Choose sample set:", choices=names(lox@count_matrixes)),
actionButton("delete_sample", "Delete Sample Set")
),
box(
width = 6,
title = "Edit sample sets",
status = NULL,
color = "red",
solidHeader = TRUE,
collapsible = TRUE,
textInput("name_sample", label="Name of new sample set:", placeholder="Sample Set Name"),
fluidRow(
column(4, actionButton("create_sample", "Create from Selection")),
column(4, actionButton("create_all_sample", "Create from All")),
column(4, actionButton("rename_sample", "Rename Current"))
)
),
box(
width = 12,
title = "Sample Set Table",
status = "danger",
solidHeader = FALSE,
wellPanel(dataTableOutput("sample_table")),
verbatimTextOutput("selected_samples"),
),
box(
width = 6,
title = "Generate aliases",
status = NULL,
solidHeader = TRUE,
collapsible = TRUE,
collapsed = TRUE,
checkboxGroupInput("alias_parameters", "Choose alias parameters:", choices=c("")),
actionButton("generate_alias", "Generate")
),
box(
width = 6,
title = "Collapse samples",
status = NULL,
solidHeader = TRUE,
collapsible = TRUE,
collapsed = TRUE,
textInput("collapse_name", label="Name of new sample set:", placeholder="Sample Set Name"),
tags$strong("Collapse type: "),
fluidRow(
column(3, checkboxInput("collapse_union", "Union")),
column(3, checkboxInput("collapse_average", "Average"))
),
checkboxGroupInput("collapse_parameters", "Choose parameters to collapse:", choices=c("")),
actionButton("collapse_samples", "Collapse"),
actionButton("collapse_selection", "Collapse selected")
)
)
),
tabItem(
tabName = "codes-filter",
box(
width = 6,
title = "View codes",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("independent_samples", label="Sample Set", choices=names(lox@count_matrixes)),
selectInput("filter_codeset", label="Code Set", choices=c()),
),
box(
width = 6,
title = "Filter parameters",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
column(6, sliderInput("filter_reps", label="Maximum allowed code repetitions", min=1, max=10, value=1)),
column(6, sliderInput("filter_tolerance", label="Tolerance Level (%)", min=0.1, max=100, value=5, step=0.1)),
textInput("filter_code_name", label="Name of new filtered code set:", placeholder="Code Set Name"),
actionButton("create_filtered", "Create Filtered Code Set")
),
box(
width = 6,
status = "danger",
title = "Unfiltered codes",
collapsible = TRUE,
collapsed = TRUE,
plotOutput("unfiltered_codes"),
),
box(
width = 6,
status = "danger",
title = "Filtered codes",
collapsible = TRUE,
collapsed = TRUE,
plotOutput("filtered_codes"),
),
),
tabItem(
tabName = "stats-plot",
fluidRow(
box(
title = "View a sample set",
width = 4,
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("matrix_stats", "Sample:", choices = names(lox@count_matrixes))
),
box(
title = "View a code set",
width = 4,
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("codeset_stats", "Codes:", choices = names(lox@code_sets))
),
box(
title = "Configure the plot",
width = 4,
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("labels_stats", "Plot Labels:", choices = c("sample", "alias"), selected = "alias")
),
box(
width = 12,
title = "Statistics Plots",
status = "danger",
collapsible = TRUE,
collapsed = TRUE,
tabsetPanel(
type = "tabs",
tabPanel(
"Size",
plotlyOutput("size_plot"),
checkboxInput("fill_size", "Fill"),
actionButton("includeSize", "Add to report")),
tabPanel(
"Complexity",
plotlyOutput("complexity_plot"),
checkboxInput("fill_complexity", "Fill"),
actionButton("includeComplexity", "Add to report")),
tabPanel("Ratio", plotlyOutput("ratio_plot"), actionButton("includeRatio", "Add to report")),
tabPanel("Both", plotlyOutput("both_plot"), actionButton("includeBoth", "Add to report"))
)
),
box(
width = 6,
title = "Sample Size Plot",
status = "danger",
collapsible = TRUE,
collapsed = TRUE,
conditionalPanel(
condition = "input.labels_stats=='sample'",
selectInput("size_sample", "", choices=c()),
),
conditionalPanel(
condition = "input.labels_stats=='alias'",
selectInput("size_alias", "", choices=c()),
),
plotlyOutput("sample_size_plot"),
actionButton("includeSampleSize", "Add to report")
),
box(
width = 6,
title = "Sample Complexity Plot",
status = "danger",
collapsible = TRUE,
collapsed = TRUE,
conditionalPanel(
condition = "input.labels_stats=='sample'",
selectInput("complexity_sample", "", choices=c()),
),
conditionalPanel(
condition = "input.labels_stats=='alias'",
selectInput("complexity_alias", "", choices=c()),
),
plotlyOutput("sample_complexity_plot"),
actionButton("includeSampleComplexity", "Add to report")
)
)
),
tabItem(
tabName = "heatmap-plot",
box(
width = 6,
title = "View a sample set",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("matrix_heat", "Sample:", choices = names(lox@count_matrixes))
),
box(
width = 6,
title = "View a code set",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("codeset_heat", "Codes:", choices = names(lox@code_sets))
),
box(
width = 6,
title = "Sample Comparison Pie",
status = "danger",
color = NULL,
collapsible = TRUE,
collapsed = TRUE,
plotOutput("sample_comparison_pie"),
textInput("scale_pie", "Scale factor:", value=1)
),
box(
width = 6,
title = "Configure the heatmap plot",
status = "danger",
color = NULL,
collapsible = TRUE,
collapsed = TRUE,
selectInput("type_heat", "Plot Types:", choices = c("ggplot", "plotly")),
selectInput("labels_heat", "Plot Labels:", choices=c("sample", "alias"), selected = "alias"),
selectInput("clustering", "Clustering", choices=c("none", "row", "col", "both")),
selectInput("agglomeration", "Agglomeration", choices=c("ward.D", "ward.D2", "single", "complete", "average", "mcquitty", "median","centroid","binary"),selected="complete"),
sliderInput("min_reads", label="Minimum # reads", min=1, max=100, value=1),
sliderInput("max_repeats", label="Maximum # repeats", min=1, max=100, value=100),
sliderInput("min_repeats", label="Minimum # repeats", min=1, max=100, value=1)
),
box(
width = 12,
title = "Heat Map",
status = "danger",
color = NULL,
collapsible = TRUE,
collapsed = TRUE,
conditionalPanel(
condition = "input.type_heat=='ggplot'",
plotOutput("heatmap_ggplot")
),
conditionalPanel(
condition = "input.type_heat=='plotly'",
plotlyOutput("heatmap_plotly")
),
actionButton("includeHeatmap", "Add to report")
),
box(
width = 12,
title = "Bubble Map",
status = "danger",
color = NULL,
collapsible = TRUE,
collapsed = TRUE,
conditionalPanel(
condition = "input.type_heat=='ggplot'",
plotOutput("bubble_ggplot")
),
conditionalPanel(
condition = "input.type_heat=='plotly'",
plotlyOutput("bubble_plotly")
),
actionButton("includeBubble", "Add to report")
),
),
tabItem(
tabName = "saturation-plot",
box(
width = 6,
title = "View a sample set",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("sampleset_sat", "Sample sets:", choices = names(lox@count_matrixes)),
selectInput("name_sat", "Plot labels", choices = c("sample", "alias"), selected = "alias")
),
box(
width = 6,
title = "View plot",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
conditionalPanel(
condition = "input.name_sat=='sample'",
selectInput("sample_sat", "Samples:", choices = names(lox@samples))
),
conditionalPanel(
condition = "input.name_sat=='alias'",
selectInput("alias_sat", "Samples:", choices = lox@alias[["all_samples"]]$alias)
),
selectInput("codeset_sat", "Codes:", choices = names(lox@code_sets)),
actionButton("add_sat", "Add new"),
actionButton("remove_sat", "Remove"),
actionButton("clear_sat", "Clear")
),
box(
width = 12,
title = "Saturation Plot",
status = "danger",
collapsible = TRUE,
collapsed = TRUE,
plotlyOutput("saturation"),
actionButton("includeSaturation", "Add to report")
)
),
tabItem(
tabName = "pair-plot",
box(
width = 6,
title = "Choose your samples",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("sampleset_pair", "Sample sets:", choices = names(lox@alias)),
selectInput("codeset_pair", "Code Sets:", choices = names(lox@code_sets)),
selectInput("name_pair", "Plot labels", choices = c("sample", "alias"), selected = "alias"),
conditionalPanel(
condition = "input.name_pair=='sample'",
selectInput("sample1_pair", "Samples:", choices = c()),
selectInput("sample2_pair", "Samples:", choices = c())
),
conditionalPanel(
condition = "input.name_pair=='alias'",
selectInput("alias1_pair", "Samples:", choices = c()),
selectInput("alias2_pair", "Samples:", choices = c())
),
actionButton("add_pair", "Add new plot"),
actionButton("remove_pair", "Remove plot"),
actionButton("clear_pair", "Clear plots"),
),
box(
width = 6,
title = "Configure the plot",
status = NULL,
color = NULL,
solidHeader = TRUE,
collapsible = TRUE,
selectInput("type_pair", "Plot type", choices = c("ggplot", "plotly")),
selectInput("colour_pair", "Colour by:", choices = c("size", "dist_orig", "firstread")),
sliderInput("complexity_slider_pair", "Filter Distance Origin Range:", min = 0, max = 0, value = c(0,0)),
sliderInput("size_slider_pair", "Filter Size Range:", min = 0, max = 0, value = c(0,0)),
sliderInput("firstread_slider_pair", "Filter Firstreads Range", min = 0, max = 0, value = c(0,0))
),
box(
width = 12,
title = "Pair Comparison Plot",
status = "danger",
collapsible = TRUE,
collapsed = TRUE,
conditionalPanel(
condition = "input.type_pair=='ggplot'",
plotOutput("pair_ggplot"),
),
conditionalPanel(
condition = "input.type_pair=='plotly'",
plotlyOutput("pair_plotly"),
),
actionButton("includePair", "Add to report")
)
),
tabItem(
tabName = "report",
box(
width = 12,
title = "Generate report",
solidHeader = TRUE,
radioButtons("format", "Document format", c("PDF", "HTML", "Word"), inline = TRUE),
downloadButton("downloadReport")
),
box(
width = 12,
status = "danger",
title = "Report Components",
dataTableOutput("components_table"),
actionButton("remove_component", "Remove")
)
),
tabItem(
tabName = "log",
box(
width = 12,
title = "Actions",
solidHeader = TRUE,
actionButton("restart", "Restart", icon=icon("refresh")),
bookmarkButton(),
downloadButton("downloadLog"),
),
box(
width = 12,
status = "danger",
title = "Activity Log",
collapsible = TRUE,
collapsed = TRUE,
dataTableOutput("log_table")
)
)
)
)
# Define the js method that resets the page
jsResetCode <- "shinyjs.reset = function() {history.go(0)}"
enableBookmarking(store = "server")
ui <- function(request) {
fluidPage(
useShinyalert(),
useShinyjs(),
extendShinyjs(text=jsResetCode, functions=c("reset")),
dashboardPage(header, sidebar, body, skin = "red")
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.