Skip to content

Commit aa1ad07

Browse files
author
Ryan Patrick Kyle
committed
🔪 random ws of unknown origin
1 parent f828d58 commit aa1ad07

1 file changed

Lines changed: 72 additions & 72 deletions

File tree

R/dash.R

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@
8282
#' receive the results (via the [output] object). The events that
8383
#' trigger the callback are then described by the [input] (and/or [state])
8484
#' object(s) (which should reference layout components), which become
85-
#' argument values for R callback handlers defined in `func`. Here `func` may
86-
#' either be an anonymous R function, or a call to `clientsideFunction()`, which
87-
#' describes a locally served JavaScript function instead. The latter defines a
88-
#' "clientside callback", which updates components without passing data to and
89-
#' from the Dash backend. The latter may offer improved performance relative
85+
#' argument values for R callback handlers defined in `func`. Here `func` may
86+
#' either be an anonymous R function, or a call to `clientsideFunction()`, which
87+
#' describes a locally served JavaScript function instead. The latter defines a
88+
#' "clientside callback", which updates components without passing data to and
89+
#' from the Dash backend. The latter may offer improved performance relative
9090
#' to callbacks written in R.
9191
#' }
9292
#' \item{`callback_context()`}{
93-
#' The `callback_context` method permits retrieving the inputs which triggered
94-
#' the firing of a given callback, and allows introspection of the input/state
95-
#' values given their names. It is only available from within a callback;
93+
#' The `callback_context` method permits retrieving the inputs which triggered
94+
#' the firing of a given callback, and allows introspection of the input/state
95+
#' values given their names. It is only available from within a callback;
9696
#' attempting to use this method outside of a callback will result in a warning.
9797
#' }
9898
#' \item{`run_server(host = Sys.getenv('DASH_HOST', "127.0.0.1"),
@@ -512,20 +512,20 @@ Dash <- R6::R6Class(
512512
route$add_handler("get", dash_reload_hash, function(request, response, keys, ...) {
513513
modified_files <- private$modified_since_reload
514514
hard <- TRUE
515-
515+
516516
if (is.null(modified_files)) {
517517
# dash-renderer requires that this element not be NULL
518518
modified_files <- list()
519519
}
520-
520+
521521
resp <- list(files = modified_files,
522522
hard = hard,
523-
packages = c("dash_renderer",
523+
packages = c("dash_renderer",
524524
unique(
525525
vapply(
526-
private$dependencies,
527-
function(x) x[["name"]],
528-
FUN.VALUE=character(1),
526+
private$dependencies,
527+
function(x) x[["name"]],
528+
FUN.VALUE=character(1),
529529
USE.NAMES = FALSE)
530530
)
531531
),
@@ -537,21 +537,21 @@ Dash <- R6::R6Class(
537537
private$modified_since_reload <- list()
538538
TRUE
539539
})
540-
540+
541541
router$add_route(route, "dashR-endpoints")
542542
server$attach(router)
543-
543+
544544
server$on("start", function(server, ...) {
545545
private$generateReloadHash()
546546
private$index()
547-
547+
548548
use_viewer <- !(is.null(getOption("viewer"))) && (dynGet("use_viewer") == TRUE)
549549
host <- dynGet("host")
550550
port <- dynGet("port")
551-
551+
552552
app_url <- paste0("http://", host, ":", port)
553-
554-
if (use_viewer && host %in% c("localhost", "127.0.0.1"))
553+
554+
if (use_viewer && host %in% c("localhost", "127.0.0.1"))
555555
rstudioapi::viewer(app_url)
556556
else if (use_viewer) {
557557
warning("\U{26A0} RStudio viewer not supported; ensure that host is 'localhost' or '127.0.0.1' and that you are using RStudio to run your app. Opening default browser...")
@@ -626,13 +626,13 @@ Dash <- R6::R6Class(
626626
# ------------------------------------------------------------------------
627627
# convenient fiery wrappers
628628
# ------------------------------------------------------------------------
629-
run_server = function(host = Sys.getenv('DASH_HOST', "127.0.0.1"),
630-
port = Sys.getenv('DASH_PORT'),
631-
block = TRUE,
632-
showcase = FALSE,
629+
run_server = function(host = Sys.getenv('DASH_HOST', "127.0.0.1"),
630+
port = Sys.getenv('DASH_PORT'),
631+
block = TRUE,
632+
showcase = FALSE,
633633
use_viewer = FALSE,
634-
dev_tools_prune_errors = TRUE,
635-
debug = Sys.getenv('DASH_DEBUG'),
634+
dev_tools_prune_errors = TRUE,
635+
debug = Sys.getenv('DASH_DEBUG'),
636636
dev_tools_ui = Sys.getenv('DASH_UI'),
637637
dev_tools_props_check = Sys.getenv('DASH_PROPS_CHECK'),
638638
dev_tools_hot_reload = Sys.getenv('DASH_HOT_RELOAD'),
@@ -645,30 +645,30 @@ Dash <- R6::R6Class(
645645
# fiery is attempting to launch a server within a server, abort gracefully
646646
return(NULL)
647647
}
648-
648+
649649
getServerParam <- function(value, type, default) {
650650
if (value != "" && length(value) != 0 && mode(value) == type && !is.na(value)) {
651651
return(value)
652652
} else {
653653
return(default)
654654
}
655655
}
656-
656+
657657
self$server$host <- getServerParam(host, "character", "127.0.0.1")
658658
self$server$port <- getServerParam(as.integer(port), "numeric", 8050)
659-
659+
660660
dev_tools_ui <- getServerParam(dev_tools_ui, "logical", NULL)
661661
dev_tools_props_check <- getServerParam(dev_tools_props_check, "logical", NULL)
662-
663-
debug <- getServerParam(debug, "logical", FALSE)
664-
662+
663+
debug <- getServerParam(debug, "logical", FALSE)
664+
665665
if(getAppPath() != FALSE) {
666666
source_dir <- dirname(getAppPath())
667667
private$app_root_modtime <- modtimeFromPath(source_dir, recursive = TRUE, asset_path = private$assets_folder)
668668
} else {
669669
source_dir <- NULL
670670
}
671-
671+
672672
# set the modtime to track state of the Dash app directory
673673
# this calls getAppPath, which will try three approaches to
674674
# identifying the local app path (depending on whether the app
@@ -678,7 +678,7 @@ Dash <- R6::R6Class(
678678
} else {
679679
self$config$ui <- FALSE
680680
}
681-
681+
682682
if (is.null(dev_tools_hot_reload) && debug || isTRUE(dev_tools_hot_reload)) {
683683
hot_reload <- TRUE
684684
hot_reload_interval <- getServerParam(dev_tools_hot_reload_interval, "numeric", 3)
@@ -689,7 +689,7 @@ Dash <- R6::R6Class(
689689
} else {
690690
hot_reload <- FALSE
691691
}
692-
692+
693693
if (is.null(dev_tools_silence_routes_logging) && debug || isTRUE(dev_tools_silence_routes_logging)) {
694694
self$config$silence_routes_logging <- TRUE
695695
} else {
@@ -704,7 +704,7 @@ Dash <- R6::R6Class(
704704

705705
private$prune_errors <- getServerParam(dev_tools_prune_errors, "logical", TRUE)
706706
private$debug <- debug
707-
707+
708708
if (hot_reload == TRUE & !(is.null(source_dir))) {
709709
self$server$on('cycle-end', function(server, ...) {
710710
# handle case where assets are not present, since we can still hot reload the app itself
@@ -716,7 +716,7 @@ Dash <- R6::R6Class(
716716
} else {
717717
permit_reload <- FALSE
718718
}
719-
719+
720720
if (permit_reload) {
721721
if (dir.exists(private$assets_folder)) {
722722
# by specifying asset_path, we can exclude assets from the root_modtime when recursive=TRUE
@@ -734,17 +734,17 @@ Dash <- R6::R6Class(
734734
updated_assets <- FALSE
735735
private$app_root_modtime <- current_root_modtime
736736
}
737-
737+
738738
if (!is.null(current_asset_modtime) && updated_assets) {
739739
# refreshAssetMap silently returns a list of updated objects in the map
740740
# we can use this to retrieve the modified files, and also determine if
741741
# any are scripts or other non-CSS data
742742
has_assets <- file.exists(file.path(source_dir, private$assets_folder))
743-
743+
744744
if (length(has_assets) != 0 && has_assets) {
745745
updated_files <- private$refreshAssetMap()
746746
file_extensions <- tools::file_ext(updated_files$modified)
747-
747+
748748
# if the vector of file_extensions is logical(0), this ensures
749749
# we return FALSE instead of logical(0)
750750
checkIfCSS <- function(extension) {
@@ -753,15 +753,15 @@ Dash <- R6::R6Class(
753753
else
754754
return(extension == "css")
755755
}
756-
756+
757757
all_updated <- c(updated_files$added, updated_files$modified)
758-
private$modified_since_reload <- lapply(setNames(all_updated, NULL),
758+
private$modified_since_reload <- lapply(setNames(all_updated, NULL),
759759
function(current_file) {
760760
list(is_css = checkIfCSS(tools::file_ext(current_file)),
761761
modified = modtimeFromPath(current_file),
762762
url = paste(private$assets_url_path, basename(current_file), sep="/"))
763763
})
764-
764+
765765
private$asset_modtime <- current_asset_modtime
766766
# update the hash passed back to the renderer, and bump the timestamp
767767
# to match the current reloading event
@@ -770,15 +770,15 @@ Dash <- R6::R6Class(
770770
other_deleted <- any(tools::file_ext(updated_files$deleted) != "css")
771771
}
772772
}
773-
773+
774774
if (updated_assets || updated_root) {
775775
self$config$reload_hash <- private$generateReloadHash()
776776
flush.console()
777-
777+
778778
# if any filetypes other than CSS are encountered in those which
779779
# are modified or deleted, restart the server
780780
hard_reload <- updated_root || (has_assets && (other_changed || other_added || other_deleted))
781-
781+
782782
if (!hard_reload) {
783783
# refresh the index but don't restart the server
784784
private$index()
@@ -801,13 +801,13 @@ Dash <- R6::R6Class(
801801
}
802802
}
803803
}
804-
804+
805805
# reset the timestamp so we're able to determine when the last cycle end occurred
806806
private$last_cycle <- as.integer(Sys.time())
807807
})
808808
} else if (hot_reload == TRUE & is.null(source_dir)) {
809809
message("\U{26A0} No source directory information available; hot reloading has been disabled.\nPlease ensure that you are loading your Dash for R application using source().\n")
810-
}
810+
}
811811
self$server$ignite(block = block, showcase = showcase, ...)
812812
}
813813
),
@@ -826,15 +826,15 @@ Dash <- R6::R6Class(
826826
css = NULL,
827827
scripts = NULL,
828828
other = NULL,
829-
829+
830830
# initialize flags for debug mode and stack pruning
831831
debug = NULL,
832832
prune_errors = NULL,
833833
stack_message = NULL,
834-
834+
835835
# callback context
836-
callback_context_ = NULL,
837-
836+
callback_context_ = NULL,
837+
838838
# fields for setting modification times and paths to track state
839839
asset_modtime = NULL,
840840
app_launchtime = NULL,
@@ -844,12 +844,12 @@ Dash <- R6::R6Class(
844844
last_refresh = NULL,
845845
last_cycle = NULL,
846846
modified_since_reload = NULL,
847-
847+
848848
# fields for tracking HTML dependencies
849849
dependencies = list(),
850850
dependencies_user = list(),
851851
dependencies_internal = list(),
852-
852+
853853
# layout stuff
854854
layout_ = NULL,
855855
layout_ids = NULL,
@@ -946,11 +946,11 @@ Dash <- R6::R6Class(
946946
} else {
947947
private$asset_modtime <- modtimeFromPath(private$assets_folder, recursive = TRUE)
948948
}
949-
949+
950950
# before refreshing the asset map, temporarily store it for the
951-
# comparison with the updated map
951+
# comparison with the updated map
952952
previous_map <- private$asset_map
953-
953+
954954
# refresh the asset map
955955
current_map <- private$walk_assets_directory(private$assets_folder)
956956

@@ -962,25 +962,25 @@ Dash <- R6::R6Class(
962962
# assets; this returns a list whose subelements correspond to each
963963
# class, and three vectors of updated objects for each (deleted,
964964
# changed, and new files)
965-
list_of_diffs <- mapply(changedAssets,
966-
previous_map,
967-
current_map,
965+
list_of_diffs <- mapply(changedAssets,
966+
previous_map,
967+
current_map,
968968
SIMPLIFY=FALSE)
969-
969+
970970
# these lines collapse the modified assets into vectors, and scrub
971971
# duplicated NULL return values
972972
deleted <- unlist(lapply(list_of_diffs, `[`, "deleted"))
973973
changed <- unlist(lapply(list_of_diffs, `[`, "changed"))
974974
new <- unlist(lapply(list_of_diffs, `[`, "new"))
975-
975+
976976
# update the asset map
977977
private$asset_map <- current_map
978-
978+
979979
# when the asset map is refreshed, this function will invisibly
980980
# return the vectors of updated assets, grouped by deleted,
981981
# modified, and added files
982982
private$last_refresh <- as.integer(Sys.time())
983-
983+
984984
return(invisible(list(deleted=deleted,
985985
modified=changed,
986986
added=new)))
@@ -990,7 +990,7 @@ Dash <- R6::R6Class(
990990
return(NULL)
991991
}
992992
},
993-
993+
994994
walk_assets_directory = function(assets_dir = private$assets_folder) {
995995
# obtain the full canonical path
996996
asset_path <- normalizePath(file.path(assets_dir))
@@ -1079,8 +1079,8 @@ Dash <- R6::R6Class(
10791079

10801080
# set attributes for the return object to include the file
10811081
# modification times for each entry in the asset_map
1082-
return(list(css = setModtimeAsAttr(css_map),
1083-
scripts = setModtimeAsAttr(scripts_map),
1082+
return(list(css = setModtimeAsAttr(css_map),
1083+
scripts = setModtimeAsAttr(scripts_map),
10841084
other = setModtimeAsAttr(other_files_map)
10851085
)
10861086
)
@@ -1111,21 +1111,21 @@ Dash <- R6::R6Class(
11111111
# akin to https://github.com/plotly/dash/blob/d2ebc837/dash/dash.py#L338
11121112
# note discussion here https://github.com/plotly/dash/blob/d2ebc837/dash/dash.py#L279-L284
11131113
.index = NULL,
1114-
1114+
11151115
generateReloadHash = function() {
11161116
last_update_time <- max(as.integer(private$app_root_modtime),
11171117
as.integer(private$asset_modtime),
11181118
as.integer(private$app_launchtime),
11191119
na.rm=TRUE)
1120-
1120+
11211121
# update the timestamp to reflect the current reloading event
11221122
private$last_reload <- as.integer(Sys.time())
1123-
1123+
11241124
digest::digest(as.character(last_update_time),
11251125
"md5",
11261126
serialize = FALSE)
11271127
},
1128-
1128+
11291129
collect_resources = function() {
11301130
# Dash's own dependencies
11311131
# serve the dev version of dash-renderer when in debug mode
@@ -1199,7 +1199,7 @@ Dash <- R6::R6Class(
11991199
local = FALSE)
12001200

12011201
# collect JS assets from dependencies
1202-
#
1202+
#
12031203
if (!(is.null(private$asset_map$scripts))) {
12041204
scripts_assets <- generate_js_dist_html(href = paste0(private$assets_url_path, names(private$asset_map$scripts)),
12051205
local = TRUE,

0 commit comments

Comments
 (0)