@@ -207,140 +207,142 @@ createAppHandlers <- function(httpHandlers, serverFuncSource) {
207
207
shinysession $ setShowcase(.globals $ showcaseDefault )
208
208
209
209
ws $ onMessage(function (binary , msg ) {
210
- # To ease transition from websockets-based code. Should remove once we're stable.
211
- if (is.character(msg ))
212
- msg <- charToRaw(msg )
213
-
214
- if (isTRUE(getOption(' shiny.trace' ))) {
215
- if (binary )
216
- message(" RECV " , ' $$binary data$$' )
217
- else
218
- message(" RECV " , rawToChar(msg ))
219
- }
210
+ withReactiveDomain(shinysession , {
211
+ # To ease transition from websockets-based code. Should remove once we're stable.
212
+ if (is.character(msg ))
213
+ msg <- charToRaw(msg )
214
+
215
+ if (isTRUE(getOption(' shiny.trace' ))) {
216
+ if (binary )
217
+ message(" RECV " , ' $$binary data$$' )
218
+ else
219
+ message(" RECV " , rawToChar(msg ))
220
+ }
220
221
221
- if (identical(charToRaw(" \0 03\x e9" ), msg ))
222
- return ()
222
+ if (identical(charToRaw(" \0 03\x e9" ), msg ))
223
+ return ()
223
224
224
- msg <- decodeMessage(msg )
225
+ msg <- decodeMessage(msg )
225
226
226
- # Do our own list simplifying here. sapply/simplify2array give names to
227
- # character vectors, which is rarely what we want.
228
- if (! is.null(msg $ data )) {
229
- for (name in names(msg $ data )) {
230
- val <- msg $ data [[name ]]
227
+ # Do our own list simplifying here. sapply/simplify2array give names to
228
+ # character vectors, which is rarely what we want.
229
+ if (! is.null(msg $ data )) {
230
+ for (name in names(msg $ data )) {
231
+ val <- msg $ data [[name ]]
231
232
232
- splitName <- strsplit(name , ' :' )[[1 ]]
233
- if (length(splitName ) > 1 ) {
234
- msg $ data [[name ]] <- NULL
233
+ splitName <- strsplit(name , ' :' )[[1 ]]
234
+ if (length(splitName ) > 1 ) {
235
+ msg $ data [[name ]] <- NULL
235
236
236
- if (! inputHandlers $ containsKey(splitName [[2 ]])){
237
- # No input handler registered for this type
238
- stop(" No handler registered for for type " , name )
239
- }
237
+ if (! inputHandlers $ containsKey(splitName [[2 ]])){
238
+ # No input handler registered for this type
239
+ stop(" No handler registered for for type " , name )
240
+ }
240
241
241
- msg $ data [[ splitName [[1 ]] ]] <-
242
+ msg $ data [[ splitName [[1 ]] ]] <-
242
243
inputHandlers $ get(splitName [[2 ]])(
243
- val ,
244
- shinysession ,
245
- splitName [[1 ]] )
246
- }
247
- else if (is.list(val ) && is.null(names(val ))) {
248
- val_flat <- unlist(val , recursive = TRUE )
249
-
250
- if (is.null(val_flat )) {
251
- # This is to assign NULL instead of deleting the item
252
- msg $ data [name ] <- list (NULL )
253
- } else {
254
- msg $ data [[name ]] <- val_flat
244
+ val ,
245
+ shinysession ,
246
+ splitName [[1 ]] )
247
+ }
248
+ else if (is.list(val ) && is.null(names(val ))) {
249
+ val_flat <- unlist(val , recursive = TRUE )
250
+
251
+ if (is.null(val_flat )) {
252
+ # This is to assign NULL instead of deleting the item
253
+ msg $ data [name ] <- list (NULL )
254
+ } else {
255
+ msg $ data [[name ]] <- val_flat
256
+ }
255
257
}
256
258
}
257
259
}
258
- }
259
260
260
- switch (
261
- msg $ method ,
262
- init = {
263
-
264
- serverFunc <- serverFuncSource()
265
- if (! identicalFunctionBodies(serverFunc , appvars $ server )) {
266
- appvars $ server <- serverFunc
267
- if (! is.null(appvars $ server ))
268
- {
269
- # Tag this function as the Shiny server function. A debugger may use this
270
- # tag to give this function special treatment.
271
- # It's very important that it's appvars$server itself and NOT a copy that
272
- # is invoked, otherwise new breakpoints won't be picked up.
273
- attr(appvars $ server , " shinyServerFunction" ) <- TRUE
274
- registerDebugHook(" server" , appvars , " Server Function" )
261
+ switch (
262
+ msg $ method ,
263
+ init = {
264
+
265
+ serverFunc <- withReactiveDomain(NULL , serverFuncSource())
266
+ if (! identicalFunctionBodies(serverFunc , appvars $ server )) {
267
+ appvars $ server <- serverFunc
268
+ if (! is.null(appvars $ server ))
269
+ {
270
+ # Tag this function as the Shiny server function. A debugger may use this
271
+ # tag to give this function special treatment.
272
+ # It's very important that it's appvars$server itself and NOT a copy that
273
+ # is invoked, otherwise new breakpoints won't be picked up.
274
+ attr(appvars $ server , " shinyServerFunction" ) <- TRUE
275
+ registerDebugHook(" server" , appvars , " Server Function" )
276
+ }
275
277
}
276
- }
277
278
278
- # Check for switching into/out of showcase mode
279
- if (.globals $ showcaseOverride &&
280
- exists(" .clientdata_url_search" , where = msg $ data )) {
281
- mode <- showcaseModeOfQuerystring(msg $ data $ .clientdata_url_search )
282
- if (! is.null(mode ))
283
- shinysession $ setShowcase(mode )
284
- }
279
+ # Check for switching into/out of showcase mode
280
+ if (.globals $ showcaseOverride &&
281
+ exists(" .clientdata_url_search" , where = msg $ data )) {
282
+ mode <- showcaseModeOfQuerystring(msg $ data $ .clientdata_url_search )
283
+ if (! is.null(mode ))
284
+ shinysession $ setShowcase(mode )
285
+ }
285
286
286
- shinysession $ manageInputs(msg $ data )
287
+ shinysession $ manageInputs(msg $ data )
287
288
288
- # The client tells us what singletons were rendered into
289
- # the initial page
290
- if (! is.null(msg $ data $ .clientdata_singletons )) {
291
- shinysession $ singletons <<- strsplit(
292
- msg $ data $ .clientdata_singletons , ' ,' )[[1 ]]
293
- }
289
+ # The client tells us what singletons were rendered into
290
+ # the initial page
291
+ if (! is.null(msg $ data $ .clientdata_singletons )) {
292
+ shinysession $ singletons <<- strsplit(
293
+ msg $ data $ .clientdata_singletons , ' ,' )[[1 ]]
294
+ }
294
295
295
- local({
296
- args <- list (
297
- input = shinysession $ input ,
298
- output = .createOutputWriter(shinysession ))
296
+ local({
297
+ args <- list (
298
+ input = shinysession $ input ,
299
+ output = .createOutputWriter(shinysession ))
299
300
300
- # The clientData and session arguments are optional; check if
301
- # each exists
302
- if (' clientData' %in% names(formals(serverFunc )))
303
- args $ clientData <- shinysession $ clientData
301
+ # The clientData and session arguments are optional; check if
302
+ # each exists
303
+ if (' clientData' %in% names(formals(serverFunc )))
304
+ args $ clientData <- shinysession $ clientData
304
305
305
- if (' session' %in% names(formals(serverFunc )))
306
- args $ session <- shinysession
306
+ if (' session' %in% names(formals(serverFunc )))
307
+ args $ session <- shinysession
307
308
308
- withReactiveDomain(shinysession , {
309
- do.call(appvars $ server , args )
309
+ withReactiveDomain(shinysession , {
310
+ do.call(appvars $ server , args )
311
+ })
310
312
})
311
- })
312
- },
313
- update = {
314
- shinysession $ manageInputs( msg $ data )
315
- },
316
- shinysession $ dispatch( msg )
317
- )
318
- shinysession $ manageHiddenOutputs()
319
-
320
- if ( exists(" .shiny__stdout " , globalenv( )) &&
321
- exists( " HTTP_GUID " , ws $ request )) {
322
- # safe to assume we're in shiny-server
323
- shiny_stdout <- get( " .shiny__stdout " , globalenv())
324
-
325
- # eNter a flushReact
326
- writeLines(paste( " _n_flushReact " , get( " HTTP_GUID " , ws $ request ),
327
- " @ " , sprintf( " %.3f " , as.numeric(Sys.time())),
328
- sep = " " ), con = shiny_stdout )
329
- flush( shiny_stdout )
330
-
331
- flushReact()
332
-
333
- # eXit a flushReact
334
- writeLines(paste( " _x_flushReact " , get( " HTTP_GUID " , ws $ request ),
335
- " @ " , sprintf( " %.3f " , as.numeric(Sys.time())),
336
- sep = " " ), con = shiny_stdout )
337
- flush( shiny_stdout )
338
- } else {
339
- flushReact()
340
- }
341
- lapply( appsByToken $ values(), function ( shinysession ) {
342
- shinysession $ flushOutput()
343
- NULL
313
+ },
314
+ update = {
315
+ shinysession $ manageInputs( msg $ data )
316
+ },
317
+ shinysession $ dispatch( msg )
318
+ )
319
+ shinysession $ manageHiddenOutputs( )
320
+
321
+ if (exists( " .shiny__stdout " , globalenv()) &&
322
+ exists(" HTTP_GUID " , ws $ request )) {
323
+ # safe to assume we're in shiny-server
324
+ shiny_stdout <- get( " .shiny__stdout " , globalenv())
325
+
326
+ # eNter a flushReact
327
+ writeLines(paste( " _n_flushReact " , get( " HTTP_GUID " , ws $ request ),
328
+ " @ " , sprintf( " %.3f " , as.numeric(Sys.time()) ),
329
+ sep = " " ), con = shiny_stdout )
330
+ flush( shiny_stdout )
331
+
332
+ flushReact()
333
+
334
+ # eXit a flushReact
335
+ writeLines(paste( " _x_flushReact " , get( " HTTP_GUID " , ws $ request ),
336
+ " @ " , sprintf( " %.3f " , as.numeric(Sys.time()) ),
337
+ sep = " " ), con = shiny_stdout )
338
+ flush( shiny_stdout )
339
+ } else {
340
+ flushReact()
341
+ }
342
+ lapply( appsByToken $ values(), function ( shinysession ) {
343
+ shinysession $ flushOutput()
344
+ NULL
345
+ })
344
346
})
345
347
})
346
348
0 commit comments