-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotPar.R
134 lines (127 loc) · 4.44 KB
/
plotPar.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#' Shiny Module Server for Plot Parameters
#'
#' @param id identifier
#' @param contrast_table reactive data frame
#'
#' @return reactive object
#' @importFrom shiny column fluidRow moduleServer NS observeEvent
#' radioButtons reactive reactiveVal reactiveValues renderUI
#' req selectInput tagList uiOutput updateSelectInput
#' @importFrom DT renderDataTable
#' @importFrom foundr ggplot_conditionContrasts summary_conditionContrasts
#' summary_strainstats
#' @export
#'
plotParServer <- function(id, contrast_table) {
shiny::moduleServer(id, function(input, output, session) {
ns <- session$ns
# Parameters
# ordername
# volvert
# volsd
# rownames
# interact
# Input ordername
output$ordername <- shiny::renderUI({
shiny::req(contrast_table())
orders <- c("p.value","kME","size","module")
orders <- orders[!is.na(match(orders, names(contrast_table())))]
shiny::selectInput(ns("ordername"), "Order by:", orders)
})
# Input volvert
vol <- shiny::reactive({ vol_default(shiny::req(input$ordername)) },
label = "vol")
output$volvert <- shiny::renderUI({
shiny::req(vol())
shiny::sliderInput(ns("volvert"),
paste(vol()$label, "line:"),
min = vol()$min, max = vol()$max,
value = vol()$value, step = vol()$step)
})
shiny::observeEvent(
shiny::req(contrast_table(), input$ordername, vol(), info()),
{
maxsd <- min(signif(max(abs(contrast_table()[[info()$col]]), na.rm = TRUE), 2), 5)
shiny::updateSliderInput(session, "volsd", max = maxsd)
if(input$ordername == "p.value") {
maxvert <- min(10, round(-log10(min(contrast_table()$p.value, na.rm = TRUE)), 1))
} else {
maxvert <- vol()$max
}
shiny::updateSliderInput(session, "volvert", max = maxvert)
}, label = "observeSlider")
# Input rownames
info <- shiny::reactive({
# Set up particulars for contrast or stat
if(inherits(shiny::req(contrast_table()), "conditionContrasts"))
list(row = "strain", col = "value", title = "Strains")
else
list(row = "term", col = "SD", title = "Terms")
})
output$rownames <- shiny::renderUI({
title <- shiny::req(info())$title
if(title == "Strains") {
choices <- names(foundr::CCcolors)
} else {
choices <- term_stats(contrast_table(), signal = FALSE, drop_noise = TRUE)
}
shiny::checkboxGroupInput(ns("rownames"), "",
choices = choices, selected = choices, inline = TRUE)
})
###############################################################
input
})
}
#' Shiny Module Input for Plot Parameters
#' @return nothing returned
#' @rdname plotParServer
#' @export
plotParInput <- function(id) {
ns <- shiny::NS(id)
shiny::fluidRow(
shiny::column(4, shiny::uiOutput(ns("ordername"))),
shiny::column(8, shiny::checkboxInput(ns("interact"), "Interactive?")))
}
#' Shiny Module UI for Plot Parameters
#' @return nothing returned
#' @rdname plotParServer
#' @export
plotParUI <- function(id) {
ns <- shiny::NS(id)
# Sliders from Volcano plot display.
shiny::fluidRow(
shiny::column(6, shiny::sliderInput(ns("volsd"),
"SD line:", min = 0, max = 2, value = 1, step = 0.1)),
shiny::column(6, shiny::uiOutput(ns("volvert"))))
}
#' Shiny Module Output for Plot Parameters
#' @return nothing returned
#' @rdname plotParServer
#' @export
plotParOutput <- function(id) {
ns <- shiny::NS(id)
shiny::uiOutput(ns("rownames"))
}
#' Shiny Module App for Plot Parameters
#' @return nothing returned
#' @rdname plotParServer
#' @export
plotParApp <- function() {
ui <- shiny::bootstrapPage(
mainParInput("main_par"), # dataset
shiny::h3("plot_par parameters"),
shiny::h4("plotParInput: ordername, interact"),
plotParInput("plot_par"), # ordername, interact
shiny::h4("plotParUI: volsd, volvert"),
plotParUI("plot_par"), # volsd, volvert (sliders)
shiny::h4("plotParOutput: rownames"),
plotParOutput("plot_par") # rownames (strains/terms)
)
server <- function(input, output, session) {
main_par <- mainParServer("main_par", traitStats)
contrast_table <- contrastTableServer("contrast_table", main_par,
traitSignal, traitStats, customSettings)
plot_par <- plotParServer("plot_par", contrast_table)
}
shiny::shinyApp(ui, server)
}