1919# '
2020# ' choices <- sample(as.factor(c("a", "b", "c")), size = 20, replace = TRUE)
2121# ' counts <- table(choices)
22- # ' labels <- countBarLabels (
22+ # ' labels <- countBars (
2323# ' inputId = "counts",
2424# ' choices = c("a", "b", "c"),
2525# ' countsmax = c(20, 20, 20),
4646# ' new_counts <- counts
4747# ' new_counts[!names(new_counts) %in% input$choices] <- 0
4848# '
49- # ' updateCountBarLabels (
49+ # ' updateCountBars (
5050# ' inputId = "counts",
5151# ' choices = levels(choices),
5252# ' countsmax = c(20, 20, 20),
5656# ' }
5757# ' )
5858# ' @keywords internal
59- countBarLabels <- function (inputId , choices , countsmax , countsnow = NULL ) {
59+ countBars <- function (inputId , choices , countsmax , countsnow = NULL ) {
6060 checkmate :: assert_string(inputId )
6161 checkmate :: assert_vector(choices )
6262 checkmate :: assert_numeric(countsmax , len = length(choices ))
@@ -73,7 +73,7 @@ countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
7373 countmax <- countsmax [i ]
7474 countnow <- if (is.null(countsnow )) 0 else countsnow [i ]
7575
76- countBarLabel (
76+ countBar (
7777 inputId = ns(i ),
7878 label = choice ,
7979 countmax = countmax ,
@@ -96,27 +96,14 @@ countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
9696# ' determines `<style="width: <countmax / counttotal>%""`.
9797# ' @return `shiny.tag` object with a progress bar and a label.
9898# ' @keywords internal
99- countBarLabel <- function (inputId , label , countmax , countnow = NULL , counttotal = countmax ) {
99+ countBar <- function (inputId , label , countmax , countnow = NULL , counttotal = countmax ) {
100100 checkmate :: assert_string(inputId )
101101 checkmate :: assert_string(label )
102102 checkmate :: assert_number(countmax )
103103 checkmate :: assert_number(countnow , null.ok = TRUE , upper = countmax )
104104 checkmate :: assert_number(counttotal , lower = countmax )
105105
106-
107- label_html <- countLabel(inputId = inputId , label = label , countmax = countmax , countnow = countnow )
108- progress_html <- countBar(inputId = inputId , countmax = countmax , countnow = countnow , counttotal = counttotal )
109- tags $ div(progress_html , label_html )
110- }
111-
112-
113- # ' @rdname countBarLabel
114- countBar <- function (inputId , countmax , countnow = NULL , counttotal ) {
115- checkmate :: assert_string(inputId )
116- checkmate :: assert_number(countmax )
117- checkmate :: assert_number(countnow , null.ok = TRUE )
118- checkmate :: assert_number(counttotal )
119-
106+ label <- make_count_text(label , countmax = countmax , countnow = countnow )
120107 ns <- NS(inputId )
121108 tags $ div(
122109 class = " progress state-count-container" ,
@@ -125,7 +112,8 @@ countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
125112 id = ns(" count_bar_filtered" ),
126113 class = " progress-bar state-count-bar-filtered" ,
127114 style = sprintf(" width: %s%%" , countnow / counttotal * 100 ),
128- role = " progressbar"
115+ role = " progressbar" ,
116+ label
129117 ),
130118 tags $ div(
131119 id = ns(" count_bar_unfiltered" ),
@@ -136,20 +124,8 @@ countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
136124 )
137125}
138126
139- # ' @rdname countBarLabel
140- countLabel <- function (inputId , label , countmax , countnow = NULL ) {
141- checkmate :: assert_string(inputId )
142- checkmate :: assert_string(label )
143- checkmate :: assert_number(countmax )
144- checkmate :: assert_number(countnow , null.ok = TRUE )
145-
146- ns <- NS(inputId )
147- label <- make_count_text(label = label , countmax = countmax , countnow = countnow )
148- label_html <- tags $ div(id = ns(" count_text" ), class = " state-count-text" , label )
149- }
150-
151- # ' @rdname countBarLabels
152- updateCountBarLabels <- function (session = getDefaultReactiveDomain(), inputId , choices ,
127+ # ' @rdname countBars
128+ updateCountBars <- function (session = getDefaultReactiveDomain(), inputId , choices ,
153129 countsmax , countsnow = NULL ) {
154130 checkmate :: assert_string(inputId )
155131 checkmate :: assert_vector(choices )
@@ -162,14 +138,9 @@ updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId,
162138 choice <- choices [i ]
163139 countmax <- countsmax [i ]
164140 countnow <- if (is.null(countsnow )) countmax else countsnow [i ]
165- updateCountLabel(
166- inputId = ns(i ),
167- label = choice ,
168- countmax = countmax ,
169- countnow = countnow
170- )
171141 updateCountBar(
172142 inputId = ns(i ),
143+ label = choice ,
173144 countmax = countmax ,
174145 countnow = countnow ,
175146 counttotal = counttotal
@@ -178,61 +149,46 @@ updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId,
178149 invisible (NULL )
179150}
180151
181- # ' @rdname countBarLabel
182- updateCountBarLabel <- function (session = getDefaultReactiveDomain(), inputId , label ,
152+ # ' @rdname countBar
153+ updateCountBar <- function (session = getDefaultReactiveDomain(), inputId , label ,
183154 countmax , countnow = NULL , counttotal ) {
184155 checkmate :: assert_string(inputId )
185156 checkmate :: assert_string(label )
186157 checkmate :: assert_number(countmax )
187158 checkmate :: assert_number(countnow , null.ok = TRUE )
188159 checkmate :: assert_number(counttotal )
189160
190- label <- make_count_label(label , countmax = countmax , countnow = countnow )
191161 if (is.null(countnow )) countnow <- countmax
192-
193- updateCountLabel(inputId = inputId , label = label , countmax = countmax , countnow = countnow )
194- updateCountBar(inputId = inputId , countmax = countmax , countnow = countnow , counttotal = counttotal )
195-
196- invisible (NULL )
197- }
198-
199- # ' @rdname countBarLabel
200- updateCountLabel <- function (session = getDefaultReactiveDomain(), inputId , label , countmax , countnow ) {
201- checkmate :: assert_string(inputId )
202- checkmate :: assert_string(label )
203- checkmate :: assert_number(countmax )
204- checkmate :: assert_number(countnow , null.ok = TRUE )
205-
206- label <- make_count_text(label = label , countmax = countmax , countnow = countnow )
207-
162+ label <- make_count_text(label , countmax = countmax , countnow = countnow )
208163 session $ sendCustomMessage(
209- type = " updateCountLabel " ,
164+ type = " updateCountBar " ,
210165 message = list (
211166 id = session $ ns(inputId ),
212- label = label
167+ label = label ,
168+ countmax = countmax ,
169+ countnow = countnow ,
170+ counttotal = counttotal
213171 )
214172 )
173+
174+ invisible (NULL )
215175}
216176
217- # ' @rdname countBarLabel
218- updateCountBar <- function (session = getDefaultReactiveDomain(), inputId , countmax , countnow , counttotal ) {
177+ updateCountText <- function (session = getDefaultReactiveDomain(), inputId , label , countmax , countnow ) {
219178 checkmate :: assert_string(inputId )
179+ checkmate :: assert_string(label )
220180 checkmate :: assert_number(countmax )
221181 checkmate :: assert_number(countnow , null.ok = TRUE )
222- checkmate :: assert_number(counttotal )
223-
182+ label <- make_count_text(label , countmax = countmax , countnow = countnow )
224183 session $ sendCustomMessage(
225- type = " updateCountBar " ,
184+ type = " updateCountText " ,
226185 message = list (
227186 id = session $ ns(inputId ),
228- countmax = countmax ,
229- countnow = countnow ,
230- counttotal = counttotal
187+ label = label
188+ )
231189 )
232- )
233190}
234191
235-
236192# ' Make a count text
237193# '
238194# ' Returns a text describing filtered counts. Text is composed in following way:
@@ -253,4 +209,4 @@ make_count_text <- function(label, countmax, countnow = NULL) {
253209 if (is.null(countnow )) " " else sprintf(" %s/" , countnow ),
254210 countmax
255211 )
256- }
212+ }
0 commit comments