@@ -187,6 +187,7 @@ Dash <- R6::R6Class(
187
187
private $ app_root_path <- getAppPath()
188
188
private $ app_launchtime <- as.integer(Sys.time())
189
189
private $ meta_tags <- meta_tags
190
+ private $ in_viewer <- FALSE
190
191
191
192
# config options
192
193
self $ config $ routes_pathname_prefix <- resolve_prefix(routes_pathname_prefix , " DASH_ROUTES_PATHNAME_PREFIX" )
@@ -550,19 +551,19 @@ Dash <- R6::R6Class(
550
551
server $ on(" start" , function (server , ... ) {
551
552
private $ generateReloadHash()
552
553
private $ index()
554
+
555
+ viewer <- ! (is.null(getOption(" viewer" ))) && (dynGet(" use_viewer" ) == TRUE )
553
556
554
- use_viewer <- ! (is.null(getOption(" viewer" ))) && (dynGet(" use_viewer" ) == TRUE )
555
- host <- dynGet(" host" )
556
- port <- dynGet(" port" )
557
+ app_url <- paste0(" http://" , self $ server $ host , " :" , self $ server $ port )
557
558
558
- app_url <- paste0(" http://" , host , " :" , port )
559
-
560
- if (use_viewer && host %in% c(" localhost" , " 127.0.0.1" ))
559
+ if (viewer && self $ server $ host %in% c(" localhost" , " 127.0.0.1" )) {
561
560
rstudioapi :: viewer(app_url )
562
- else if (use_viewer ) {
561
+ private $ in_viewer <- TRUE
562
+ }
563
+ else if (viewer ) {
563
564
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..." )
564
565
utils :: browseURL(app_url )
565
- }
566
+ }
566
567
})
567
568
568
569
# user-facing fields
@@ -702,7 +703,7 @@ Dash <- R6::R6Class(
702
703
hot_reload_watch_interval <- getServerParam(dev_tools_hot_reload_watch_interval , " double" , 0.5 )
703
704
hot_reload_max_retry <- getServerParam(as.integer(dev_tools_hot_reload_max_retry ), " integer" , 8 )
704
705
# convert from seconds to msec as used by js `setInterval`
705
- self $ config $ hot_reload <- list (interval = hot_reload_watch_interval * 1000 , max_retry = hot_reload_max_retry )
706
+ self $ config $ hot_reload <- list (interval = hot_reload_interval * 1000 , max_retry = hot_reload_max_retry )
706
707
} else {
707
708
hot_reload <- FALSE
708
709
}
@@ -713,14 +714,16 @@ Dash <- R6::R6Class(
713
714
if (hot_reload == TRUE & ! (is.null(source_dir ))) {
714
715
self $ server $ on(' cycle-end' , function (server , ... ) {
715
716
# handle case where assets are not present, since we can still hot reload the app itself
716
- # private$last_refresh will get set after the asset_map is refreshed
717
+ #
718
+ # private$last_refresh is set after the asset_map is refreshed
719
+ # private$last_reload stores the time of the last hard or soft reload event
717
720
# private$last_cycle will be set when the cycle-end handler terminates
718
- if ( ! is.null( private $ last_cycle ) & ! is.null( hot_reload_interval )) {
719
- # determine if the time since last cycle end is equal to or longer than the requested check interval
720
- permit_reload <- (as.integer( Sys.time()) - private $ last_cycle ) > = hot_reload_interval
721
+ #
722
+ if ( ! is.null( private $ last_cycle ) & ! is.null( hot_reload_watch_interval )) {
723
+ permit_reload <- (Sys.time() - private $ last_reload ) > = hot_reload_watch_interval
721
724
} else {
722
725
permit_reload <- FALSE
723
- }
726
+ }
724
727
725
728
if (permit_reload ) {
726
729
if (dir.exists(private $ assets_folder )) {
@@ -787,6 +790,9 @@ Dash <- R6::R6Class(
787
790
if (! hard_reload ) {
788
791
# refresh the index but don't restart the server
789
792
private $ index()
793
+ # while not a "hard" reload, update last_reload to reflect "soft" reloads also
794
+ # since we determine whether to perform subsequent reloads based this value
795
+ private $ last_reload <- as.integer(Sys.time())
790
796
} else {
791
797
# if the server was started via Rscript or via source()
792
798
# then update the app object here
@@ -800,6 +806,9 @@ Dash <- R6::R6Class(
800
806
private $ callback_map <- get(" callback_map" , envir = get(" app" , envir = app_env )$ .__enclos_env__ $ private )
801
807
private $ layout_ <- get(" layout_" , envir = get(" app" , envir = app_env )$ .__enclos_env__ $ private )
802
808
private $ index()
809
+ # if using the viewer, reload app there
810
+ if (private $ in_viewer )
811
+ rstudioapi :: viewer(paste0(" http://" , self $ server $ host , " :" , self $ server $ port ))
803
812
# tear down the temporary environment
804
813
rm(app_env )
805
814
}
@@ -846,11 +855,16 @@ Dash <- R6::R6Class(
846
855
app_launchtime = NULL ,
847
856
app_root_path = NULL ,
848
857
app_root_modtime = NULL ,
849
- last_reload = NULL ,
858
+
859
+ # fields for controlling hot reloading state
860
+ last_reload = numeric (1 ),
850
861
last_refresh = NULL ,
851
862
last_cycle = NULL ,
852
863
modified_since_reload = NULL ,
853
864
865
+ # field to store whether viewer has been requested
866
+ in_viewer = NULL ,
867
+
854
868
# fields for tracking HTML dependencies
855
869
dependencies = list (),
856
870
dependencies_user = list (),
0 commit comments