@@ -190,7 +190,7 @@ tagWrite <- function(tag, textWriter, indent=0, eol = "\n") {
190
190
# optionally process a list of tags
191
191
if (! isTag(tag ) && is.list(tag )) {
192
192
tag <- dropNullsOrEmpty(flattenTags(tag ))
193
- sapply (tag , function ( t ) tagWrite( t , textWriter , indent ) )
193
+ lapply (tag , tagWrite , textWriter , indent )
194
194
return (NULL )
195
195
}
196
196
@@ -212,7 +212,9 @@ tagWrite <- function(tag, textWriter, indent=0, eol = "\n") {
212
212
# Convert all attribs to chars explicitly; prevents us from messing up factors
213
213
attribs <- lapply(tag $ attribs , as.character )
214
214
# concatenate attributes
215
- attribs <- lapply(split(attribs , names(attribs )), paste , collapse = " " )
215
+ # split() is very slow, so avoid it if possible
216
+ if (anyDuplicated(names(attribs )))
217
+ attribs <- lapply(split(attribs , names(attribs )), paste , collapse = " " )
216
218
217
219
# write attributes
218
220
for (attrib in names(attribs )) {
@@ -235,8 +237,8 @@ tagWrite <- function(tag, textWriter, indent=0, eol = "\n") {
235
237
236
238
# special case for a single child text node (skip newlines and indentation)
237
239
if ((length(children ) == 1 ) && is.character(children [[1 ]]) ) {
238
- tagWrite( children [[1 ]], textWriter , 0 , " " )
239
- textWriter(paste( " </ " , tag $ name , " > " , eol , sep = " " ))
240
+ textWriter(paste(normalizeText( children [[1 ]]), " </ " , tag $ name , " > " , eol ,
241
+ sep = " " ))
240
242
}
241
243
else {
242
244
textWriter(" \n " )
@@ -261,11 +263,13 @@ tagWrite <- function(tag, textWriter, indent=0, eol = "\n") {
261
263
262
264
doRenderTags <- function (ui , indent = 0 ) {
263
265
# Render the body--the bodyHtml variable will be created
264
- htmlResult <- NULL
265
- conn <- textConnection(" htmlResult" , " w" , local = TRUE )
266
- connWriter <- function (text ) cat(text , file = conn )
267
- tryCatch(
268
- tagWrite(ui , connWriter , indent ),
266
+ conn <- file(open = " w+" )
267
+ connWriter <- function (text ) writeChar(text , conn , eos = NULL )
268
+ htmlResult <- tryCatch({
269
+ tagWrite(ui , connWriter , indent )
270
+ flush(conn )
271
+ readLines(conn )
272
+ },
269
273
finally = close(conn )
270
274
)
271
275
return (HTML(paste(htmlResult , collapse = " \n " )))
@@ -292,26 +296,10 @@ rewriteTags <- function(ui, func, preorder) {
292
296
if (preorder )
293
297
ui <- func(ui )
294
298
295
- if (! isTag(ui ) && is.list(ui )) {
296
- if (length(ui ) > 0 ) {
297
- for (i in 1 : length(ui )) {
298
- newVal <- rewriteTags(ui [[i ]], func , preorder )
299
- if (is.null(newVal ))
300
- ui [i ] <- list (NULL )
301
- else
302
- ui [[i ]] <- newVal
303
- }
304
- }
305
- } else if (isTag(ui )) {
306
- if (length(ui $ children ) > 0 ) {
307
- for (i in 1 : length(ui $ children )) {
308
- newVal <- rewriteTags(ui $ children [[i ]], func , preorder )
309
- if (is.null(newVal ))
310
- ui $ children [i ] <- list (NULL )
311
- else
312
- ui $ children [[i ]] <- newVal
313
- }
314
- }
299
+ if (isTag(ui )) {
300
+ ui $ children [] <- lapply(ui $ children , rewriteTags , func , preorder )
301
+ } else if (is.list(ui )) {
302
+ ui [] <- lapply(ui , rewriteTags , func , preorder )
315
303
}
316
304
317
305
if (! preorder )
@@ -331,7 +319,7 @@ rewriteTags <- function(ui, func, preorder) {
331
319
# different).
332
320
surroundSingletons <- local({
333
321
surroundSingleton <- function (uiObj ) {
334
- if (is (uiObj , " shiny.singleton" )) {
322
+ if (inherits (uiObj , " shiny.singleton" )) {
335
323
sig <- digest(uiObj , " sha1" )
336
324
class(uiObj ) <- class(uiObj )[class(uiObj ) != " shiny.singleton" ]
337
325
return (tagList(
@@ -354,7 +342,7 @@ surroundSingletons <- local({
354
342
# HTML objects and also the list of known singletons.
355
343
takeSingletons <- function (ui , singletons = character (0 ), desingleton = TRUE ) {
356
344
result <- rewriteTags(ui , function (uiObj ) {
357
- if (is (uiObj , " shiny.singleton" )) {
345
+ if (inherits (uiObj , " shiny.singleton" )) {
358
346
sig <- digest(uiObj , " sha1" )
359
347
if (sig %in% singletons )
360
348
return (NULL )
0 commit comments