From 7270c1b3c0ef187ec496615d84e000f4afc46ab2 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 27 Dec 2019 13:22:53 -0500 Subject: [PATCH 1/5] :sparkles: make public, accept relative paths --- R/dash.R | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/R/dash.R b/R/dash.R index be2597ca..c0358334 100644 --- a/R/dash.R +++ b/R/dash.R @@ -702,7 +702,40 @@ Dash <- R6::R6Class( } private$callback_context_ }, - + + # ------------------------------------------------------------------------ + # return asset URLs + # ------------------------------------------------------------------------ + get_asset_url = function(asset_path, prefix = "/") { + asset <- lapply(private$asset_map, + function(x) { + # asset_path should be prepended with the full app root & assets path + # if leading slash(es) present in asset_path, remove them before + # assembling full asset path + asset_path <- file.path(dirname(private$app_root_path), + private$assets_folder, + sub(pattern="^/+", + replacement="", + asset_path)) + + return(names(x[x == asset_path])) + } + ) + asset <- unlist(asset, use.names = FALSE) + + if (length(asset) == 0) + stop(sprintf("the asset path '%s' is not valid; please verify that this path exists within the '%s' directory.", + asset_path, + private$assets_folder)) + + # strip multiple slashes if present, since we'll + # introduce one when we concatenate the prefix and + # asset path & prepend the asset name with route prefix + return(gsub(pattern="/+", + replacement="/", + paste(prefix, asset, sep="/"))) + }, + # ------------------------------------------------------------------------ # convenient fiery wrappers # ------------------------------------------------------------------------ From c99961de1acf98c3fecd1d835efb2d08cc916f5f Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 27 Dec 2019 13:58:12 -0500 Subject: [PATCH 2/5] :see_no_evil: use assets_url_path --- R/dash.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/dash.R b/R/dash.R index c0358334..9bca8b32 100644 --- a/R/dash.R +++ b/R/dash.R @@ -733,7 +733,10 @@ Dash <- R6::R6Class( # asset path & prepend the asset name with route prefix return(gsub(pattern="/+", replacement="/", - paste(prefix, asset, sep="/"))) + paste(prefix, + private$assets_url_path, + asset, + sep="/"))) }, # ------------------------------------------------------------------------ From ec48e9a8573cccd88616b2ff1baa81a0b26971b8 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 3 Jan 2020 10:12:35 -0500 Subject: [PATCH 3/5] check env var, :rotating_light: warn if no var/not sourced --- R/dash.R | 50 +++++++++++------- ...est_multiple_outputs.cpython-27-PYTEST.pyc | Bin 0 -> 5172 bytes .../test_clientside.cpython-27-PYTEST.pyc | Bin 0 -> 1940 bytes 3 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 tests/integration/callbacks/__pycache__/test_multiple_outputs.cpython-27-PYTEST.pyc create mode 100644 tests/integration/clientside/__pycache__/test_clientside.cpython-27-PYTEST.pyc diff --git a/R/dash.R b/R/dash.R index 9bca8b32..ddb8a5eb 100644 --- a/R/dash.R +++ b/R/dash.R @@ -707,36 +707,48 @@ Dash <- R6::R6Class( # return asset URLs # ------------------------------------------------------------------------ get_asset_url = function(asset_path, prefix = "/") { + app_root_path <- Sys.getenv("DASH_APP_PATH") + + if (app_root_path == "" && getAppPath() != FALSE) { + # app loaded via source(), root path is known + app_root_path <- dirname(private$app_root_path) + } else { + # app not loaded via source(), env var not set, no reliable way to ascertain root path + warning("application not started via source(), and DASH_APP_PATH environment variable is undefined. get_asset_url returns NULL since root path cannot be reliably identified.") + return(NULL) + } + asset <- lapply(private$asset_map, function(x) { # asset_path should be prepended with the full app root & assets path # if leading slash(es) present in asset_path, remove them before # assembling full asset path - asset_path <- file.path(dirname(private$app_root_path), + asset_path <- file.path(app_root_path, private$assets_folder, sub(pattern="^/+", replacement="", asset_path)) - return(names(x[x == asset_path])) - } + } ) - asset <- unlist(asset, use.names = FALSE) - - if (length(asset) == 0) - stop(sprintf("the asset path '%s' is not valid; please verify that this path exists within the '%s' directory.", - asset_path, - private$assets_folder)) - - # strip multiple slashes if present, since we'll - # introduce one when we concatenate the prefix and - # asset path & prepend the asset name with route prefix - return(gsub(pattern="/+", - replacement="/", - paste(prefix, - private$assets_url_path, - asset, - sep="/"))) + asset <- unlist(asset, use.names = FALSE) + + if (length(asset) == 0) + stop(sprintf("the asset path '%s' is not valid; please verify that this path exists within the '%s' directory.", + asset_path, + private$assets_folder)) + + # strip multiple slashes if present, since we'll + # introduce one when we concatenate the prefix and + # asset path & prepend the asset name with route prefix + return(gsub(pattern="/+", + replacement="/", + paste(prefix, + private$assets_url_path, + asset, + sep="/"))) + } + }, # ------------------------------------------------------------------------ diff --git a/tests/integration/callbacks/__pycache__/test_multiple_outputs.cpython-27-PYTEST.pyc b/tests/integration/callbacks/__pycache__/test_multiple_outputs.cpython-27-PYTEST.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7502a8ff6b751a291e798487501cf48321f6f047 GIT binary patch literal 5172 zcmdT|TXPf16>dqsAq<$ya@kALYcLumwhRUns9L3#0;)EZT6RmoCLu*lMl&tD?a|Dn zyT?Ym)=S7!{!pIslIK+ZK%VmpQnjzice+QiBm{P#_F-kKHRtp>r~7>8oW4xuKc}j< z`~QCNuSLc}R(#6%{TyF?A5Db+5{nsoUK%`?*-nM+%&_OPmQ!Z&9P7@r=ku%-RoL?d z7R|6fL*WEzKJjK@MgA9`$6g7KW)9605sT31@9|uXWm^TR=S6|uu8&b)m~Q+a?Ph5r z5~Iia9;8Z4>&xQQ#JzFZr$IXw^=dW9GXB{be~5vuC1T&JbN8W+YjMy^bK_Mx-^Q>H z<(?NyZRu$o$NS=@SNk%LjpR_xa>K>Tpqs^_R$ql3`b1&)P^DRv?kAp%nzbk}!CF*s zY6B@J>)JFkGEFpZ^26~*`{~*C#6erc5UYKe?n$Ai8Y>j{f;bl>+I6DC>5Us6H~U1W zI{7mUs5XI-VQpF_aQ=qjhst(}qmjciS*lm-wnRe+P|Q77ZOuV0IMU)g zjKwO?P-Q}yUb7Z%%Q#XZasH1;k0jZMxJ@;*PsDweMLIt32FJWhm^SIyFR45++xPT|FPC&uqxNI-%Cb zx6pK!c(ciu0pT*gew`PfgX4;Kd0@{K8kWfcx)kfRe7j6XEo|X z7Gb}xvUq`YPq6+B_HxiCSzKk^ldL}rtF!C?LoC|CPuZ>iG>gu#Xo*E%^BE@L)dglwvz;^K)$SbARjaZ@VwkGBV#%`wnP8F^So8tA zLw3P+{$FHwF81NwRVLvP9o@HEsl+ffI64ED34tS!{csAhAH5yf zkKc^!$L04y_LEU$|5`4Py*5C0_w|G1a`%e#{_ou{{|MT!V_-|3-Duo8tv7w1G@eQtVr%PzLCo0 zK`g%&k-NHlWl!l?c(8JxAicrCLtg?lxf{7HwxO#eIXraeC6I?Z>lz)jl)eb2+G+>h z#^&ZKzqxq}&8@p=>h==l?ob~>=U6)SUX34eeAR4ue~%>RF;AW03@1p`W5> z{Tb$<*HyNQGy3}1_6F7xS*q7*qiwCzJoP#@YO$qoJWP}I!AVZrKEF$MD2(sBvzcyW zJ$p@zaREqD`CE*k=~mio>T~#6@v`2HI<81fPLH?h+MEIV5K4O;Fct71Sp42HAejwv z;T`F2Lf6S{O4~mzeD2oNmF!LK<&RJG0vty10~dp9PjLvcVB@-NJ32CneB8Nkw=#xa6NJdqT|ZGO0t{)A?XDELYz`HdSlU#t7CAfW$3 zGbx=aoiAM~&EZrzU%p(LV~hA(!ruy;!`rB{>@uq!L*mki%yb(^NqCeD7A$`dYTs|s zDq*gm8RV72A0ccgw-nnj54mO@vPDmeQr3KmhTb literal 0 HcmV?d00001 diff --git a/tests/integration/clientside/__pycache__/test_clientside.cpython-27-PYTEST.pyc b/tests/integration/clientside/__pycache__/test_clientside.cpython-27-PYTEST.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6c380ee2969985e6818eb4847564670a157abc8e GIT binary patch literal 1940 zcmcIkUvC>l5Z|+t*uJ!)ssyxe$F-HuD79O}V}mNCLLilZ9Q6T9=(M?8<4yMdurrrn z(eP5f9v_2Gzz2Yty*pp*0&iIMdS`z#v%mSb{Xg&epWpoP!#4*)B%=BB=>H}C;Cot9 z`g+0$vGCe`Ph9lH#hzH~yOW+U2O=AY#XxwC_E0Q_t@cPPMk4Ktg)h=Q@f$fhWRGXj zK6%%F(dRVsXp2NaoGGIcgkOn*Z}hp9b{(Y>R+BC1q_FCw$jTyDIl?yf6=vo(=F74S zUOWw6k(bB0x{fA3A3Zj5T~rvYNd1+*ii`$~{D3}bl6;+)1nKm6ta&${966-bWq@o6 zd72o_6m+WoLkX03*cgc9-2zKfIvZd-M<}y=I%0yB0 z<4$Q@*R2gJW;NDGHI!8Uv9q1D+-;S|b*iaH5^hNzgg*UF=m)>kf$obVvwtc?&>( zhmuvQEtOM9m z`l*t}*-+xrnBKOGUJK;Q6QiV!>%4G4ph)3Tts!DojuXFo*1d{O?Ri9ia0`4(yV)B` zJ1?UL^ literal 0 HcmV?d00001 From 67aa40aa7ab78d2e913cf2a9bea1d7bb0a205736 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 3 Jan 2020 10:12:51 -0500 Subject: [PATCH 4/5] make check more robust --- R/dash.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dash.R b/R/dash.R index ddb8a5eb..a62f0ca7 100644 --- a/R/dash.R +++ b/R/dash.R @@ -1099,7 +1099,7 @@ Dash <- R6::R6Class( # need to check whether the assets have actually been updated, since # this function is also called to generate the asset map - if (private$asset_modtime > private$app_launchtime) { + if (!is.na(private$asset_modtime) && private$asset_modtime > private$app_launchtime) { # here we use mapply to make pairwise comparisons for each of the # asset classes in the map -- before/after for css, js, and other # assets; this returns a list whose subelements correspond to each From 8589c10fd363154f6d00dd175219b4c83c33e880 Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Fri, 3 Jan 2020 11:06:36 -0500 Subject: [PATCH 5/5] :see_no_evil: indentation fix --- R/dash.R | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/R/dash.R b/R/dash.R index a62f0ca7..e12c7f70 100644 --- a/R/dash.R +++ b/R/dash.R @@ -729,26 +729,24 @@ Dash <- R6::R6Class( replacement="", asset_path)) return(names(x[x == asset_path])) - } - ) - asset <- unlist(asset, use.names = FALSE) - - if (length(asset) == 0) - stop(sprintf("the asset path '%s' is not valid; please verify that this path exists within the '%s' directory.", - asset_path, - private$assets_folder)) - - # strip multiple slashes if present, since we'll - # introduce one when we concatenate the prefix and - # asset path & prepend the asset name with route prefix - return(gsub(pattern="/+", - replacement="/", - paste(prefix, - private$assets_url_path, - asset, - sep="/"))) - } - + } + ) + asset <- unlist(asset, use.names = FALSE) + + if (length(asset) == 0) + stop(sprintf("the asset path '%s' is not valid; please verify that this path exists within the '%s' directory.", + asset_path, + private$assets_folder)) + + # strip multiple slashes if present, since we'll + # introduce one when we concatenate the prefix and + # asset path & prepend the asset name with route prefix + return(gsub(pattern="/+", + replacement="/", + paste(prefix, + private$assets_url_path, + asset, + sep="/"))) }, # ------------------------------------------------------------------------