-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgetProcessingSteps.R
133 lines (102 loc) · 3.68 KB
/
widgetProcessingSteps.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
#'
#' A widget that displays optional processing steps
#'
library(shiny)
#' Creates a widget that displays a linear process in a tabbed interface
#'
#' @param id
#' @param title
#'
#' @return
#' @export
#'
#' @examples
processingStepsWidgetUI <- function(id, title) {
ns <- NS(id)
export.buttons <- tagList(downloadButton(ns("export.html"), label = "as *.html"))
export.dropdown <- dropdownButton(ns("export"), "Export report", export.buttons, icon = icon("download"))
showdetails <- bsButton(ns("showdetails"), "Show details", type = "toggle", icon = icon("list-ul"))
return(tags$div(class = "processing-steps-widget", headerPanel(header = tagList(export.dropdown,
showdetails),
uiOutput(ns("steps.ui")))))
# titlewidget <- tags$div(class = "header", title, export)
#
# return(tags$div(class = "processing-steps-widget", bsCollapsePanel(title = title,
# uiOutput(ns("steps.ui")),
# hDivider(),
# export)))
}
#' Exports the processing steps within data as HTML
#'
#' @param filename
#' @param data
#'
#' @return
#' @export
#'
#' @examples
processingStepsWidget.exportHTML <- function(filename, data) {
steps <- tagList()
for(processing.output in data) {
output <- processing.output()
if(!is.null(output)) {
title <- paste0(length(steps) + 1, ". ", output$title)
steps <- tagAppendChild(steps, h1(title))
steps <- tagAppendChild(steps, output$content)
}
}
conn <- file(filename)
on.exit({
close(conn)
})
writeLines(paste(steps), conn)
}
#' Displays the output of the reactives in ... in the UI
#' #'
#' Processing step info functions must return NULL or a list with title and content entries.
#'
#' This function is supposed to be called by callModule. Use the one without an underscore for easier access.
#'
#' @param id
#' @param ... Reactives that return the processing information as list. Return NULL to skip the processing step.
#'
#' @return
#' @export
#'
#' @examples
processingStepsWidgetData_ <- function(input, output, session, ...) {
output$steps.ui <- renderUI({
steps <- list()
steps.titles <- c()
for(processing.output in list(...)) {
output <- processing.output()
if(!is.null(output)) {
title <- paste0(length(steps) + 1, ". ", output$title)
content <- if(input$showdetails) wellPanel(output$content) else tags$div()
steps[[length(steps) + 1]] <- tabPanel(title, content, icon = icon("chevron-right"))
steps.titles[length(steps.titles) + 1] <- title
}
}
parameters <- steps
parameters$type <- "pills"
parameters$selected <- if(length(steps.titles) > 0) steps.titles[length(steps.titles)] else NULL
return(do.call(tabsetPanel, parameters))
})
output$export.html <- downloadHandler("report.html", function(filename) {
processingStepsWidget.exportHTML(filename, list(...))
})
}
#' Displays the output of the reactives in ... in the UI
#'
#' Processing step info functions must return NULL or a list with title and content entries.
#'
#' @param id
#' @param ... Reactives that return the processing information as list. Return NULL to skip the processing step.
#'
#' @return
#' @export
#'
#' @examples
processingStepsWidgetData <- function(id, ...) {
return(callModule(processingStepsWidgetData_, id, ...))
}