Skip to content

Commit b05eaed

Browse files
author
Ryan Patrick Kyle
committed
do not hardcode react ver, more obvious field names
1 parent 724b86e commit b05eaed

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

R/dash.R

+23-13
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ Dash <- R6::R6Class(
368368
version, paste(unique(versions), collapse = "', '")
369369
), call. = FALSE)
370370
}
371-
private$react_version <- version
371+
private$react_version_enabled<- version
372372
},
373373

374374
# ------------------------------------------------------------------------
@@ -450,7 +450,8 @@ Dash <- R6::R6Class(
450450
# fields for tracking HTML dependencies
451451
dependencies = list(),
452452
dependencies_user = list(),
453-
453+
dependencies_internal = list(),
454+
454455
# layout stuff
455456
layout = welcome_page(),
456457
layout_ids = NULL,
@@ -494,7 +495,7 @@ Dash <- R6::R6Class(
494495

495496
# load package-level HTML dependencies
496497
pkgs <- unique(layout_flat[grepl("package$", layout_nms)])
497-
dashR_deps <- lapply(pkgs, function(pkg) {
498+
deps_layout <- lapply(pkgs, function(pkg) {
498499
# the objective is to identify JS dependencies
499500
# without requiring that a proprietary R format
500501
# file is loaded at object initialization to
@@ -527,7 +528,7 @@ Dash <- R6::R6Class(
527528
}
528529
})
529530

530-
dashR_deps <- unlist(dashR_deps, recursive=FALSE)
531+
deps_layout <- unlist(deps_layout, recursive=FALSE)
531532

532533
# if core components are used, but no coreGraph() exists,
533534
# don't include the plotly.js bundle
@@ -536,13 +537,16 @@ Dash <- R6::R6Class(
536537
hasGraph <- component_contains_type(layout, "dashCoreComponents", "Graph")
537538
if (hasCore && !hasGraph) {
538539
idx <- which(pkgs %in% "dashCoreComponents")
539-
scripts <- dashR_deps[[idx]][["script"]]
540-
dashR_deps[[idx]][["script"]] <- scripts[!grepl("^plotly-*", scripts)]
540+
scripts <- deps_layout[[idx]][["script"]]
541+
deps_layout[[idx]][["script"]] <- scripts[!grepl("^plotly-*", scripts)]
541542
}
542543
}
543544

544545
# add on HTML dependencies we've identified by crawling the layout
545-
private$dependencies <- c(private$dependencies, dashR_deps)
546+
private$dependencies <- c(private$dependencies, deps_layout)
547+
548+
# DashR's own dependencies
549+
private$dependencies_internal <- dashR:::.dashR_js_metadata()
546550

547551
# return the computed layout
548552
oldClass(layout) <- c("dash_layout", oldClass(layout))
@@ -586,18 +590,24 @@ Dash <- R6::R6Class(
586590
},
587591

588592
# akin to https://github.com/plotly/dash-renderer/blob/master/dash_renderer/__init__.py
589-
react_version = "15.4.2",
590-
react_deps = function() deps[grepl("^react", names(deps))],
591-
react_versions = function() vapply(private$react_deps(), "[[", character(1), "version"),
592-
593+
react_version_enabled= function() {
594+
version <- private$dependencies_internal$react$version
595+
},
596+
react_deps = function() {
597+
deps <- private$dependencies_internal
598+
deps[grepl("^react", names(deps))]
599+
},
600+
react_versions = function() {
601+
vapply(private$react_deps(), "[[", character(1), "version")
602+
},
603+
593604
# akin to https://github.com/plotly/dash/blob/d2ebc837/dash/dash.py#L338
594605
# note discussion here https://github.com/plotly/dash/blob/d2ebc837/dash/dash.py#L279-L284
595606
.index = NULL,
596607
index = function() {
597-
598608
# collect and resolve dependencies
599609
depsAll <- compact(c(
600-
private$react_deps()[private$react_versions() %in% private$react_version],
610+
private$react_deps()[private$react_versions() %in% private$react_version_enabled()],
601611
private$dependencies,
602612
private$dependencies_user,
603613
deps["dash-renderer"]

0 commit comments

Comments
 (0)