@@ -35,23 +35,17 @@ configure_logger <- function() {
35
35
}
36
36
}
37
37
38
- fix_server_reloading <- function (server ) {
39
- reparse(curly_wrap(server ))
40
- }
41
-
42
38
reparse <- function (f ) {
43
39
eval(parse(text = deparse(f )), envir = environment(f ))
44
40
}
45
41
46
- curly_wrap <- function (f ) {
47
- wrapped <- function () {
48
- do.call(f , as.list(match.call())[- 1 ])
49
- }
50
- formals(wrapped ) <- formals(f )
51
- wrapped
42
+ load_app_source <- function () {
43
+ main <- new.env(parent = globalenv())
44
+ source(fs :: path(" app" , " main.R" ), local = main )
45
+ main
52
46
}
53
47
54
- load_app <- function () {
48
+ load_app_box <- function () {
55
49
# Silence "no visible binding" notes raised by `box::use()` on R CMD check.
56
50
app <- NULL
57
51
main <- NULL
@@ -88,39 +82,36 @@ register_reload_callback <- function(callback) {
88
82
}
89
83
90
84
with_head_tags <- function (ui ) {
91
- wrap <- function (tag ) {
92
- shiny :: tagList(
93
- shiny :: tags $ head(
94
- react_support(), # Needs to go before `app.min.js`, which defines the React components.
95
- shiny :: tags $ script(src = " static/js/app.min.js" ),
96
- shiny :: tags $ link(rel = " stylesheet" , href = " static/css/app.min.css" , type = " text/css" ),
97
- shiny :: tags $ link(rel = " icon" , href = " static/favicon.ico" , sizes = " any" )
98
- ),
99
- tag
100
- )
101
- }
102
- if (is.function(ui )) {
103
- purrr :: compose(wrap , ui )
104
- } else {
105
- wrap(ui )
85
+ head <- shiny :: tags $ head(
86
+ react_support(), # Needs to go before `app.min.js`, which defines the React components.
87
+ shiny :: tags $ script(src = " static/js/app.min.js" ),
88
+ shiny :: tags $ link(rel = " stylesheet" , href = " static/css/app.min.css" , type = " text/css" ),
89
+ shiny :: tags $ link(rel = " icon" , href = " static/favicon.ico" , sizes = " any" )
90
+ )
91
+ function (request ) {
92
+ shiny :: tagList(head , ui(request ))
106
93
}
107
94
}
108
95
109
- call_ui <- function (ui , request ) {
96
+ normalize_ui <- function (ui ) {
110
97
if (! is.function(ui )) {
111
- ui
98
+ function ( request ) ui
112
99
} else if (length(formals(ui )) == 0 ) {
113
- ui()
100
+ function ( request ) ui()
114
101
} else {
115
- ui(request )
102
+ function ( request ) ui(request )
116
103
}
117
104
}
118
105
119
- call_server <- function (server , input , output , session ) {
106
+ normalize_server <- function (server ) {
120
107
if (" session" %in% formalArgs(server )) {
121
- server(input , output , session )
108
+ function (input , output , session ) {
109
+ server(input = input , output = output , session = session )
110
+ }
122
111
} else {
123
- server(input , output )
112
+ function (input , output , session ) {
113
+ server(input = input , output = output )
114
+ }
124
115
}
125
116
}
126
117
@@ -177,34 +168,36 @@ app <- function() {
177
168
if (identical(entrypoint , " app_dir" )) {
178
169
shiny :: shinyAppDir(" app" )
179
170
} else if (identical(entrypoint , " source" )) {
180
- main <- new.env()
181
- source(fs :: path(" app" , " main.R" ), local = main )
171
+ main <- load_app_source()
172
+ ui <- normalize_ui(main $ ui )
173
+ server <- main $ server
182
174
shiny :: shinyApp(
183
- ui = with_head_tags(main $ ui ),
175
+ ui = with_head_tags(ui ),
184
176
server = main $ server
185
177
)
186
178
} else if (identical(entrypoint , " box_top_level" )) {
187
- app_env <- load_app ()
179
+ app_env <- load_app_box ()
188
180
ui <- function (request ) {
189
- call_ui (app_env $ main $ ui , request )
181
+ normalize_ui (app_env $ main $ ui )( request )
190
182
}
191
183
server <- function (input , output , session ) {
192
- call_server (app_env $ main $ server , input , output , session )
184
+ normalize_server (app_env $ main $ server )( input , output , session )
193
185
}
194
186
shiny :: shinyApp(
195
187
ui = with_head_tags(ui ),
196
188
server = reparse(server )
197
189
)
198
190
} else if (is.null(entrypoint )) {
199
- app_env <- load_app()
200
- # Wrap the UI in a function to support Shiny bookmarking.
201
- ui <- function (request ) app_env $ main $ ui(" app" )
202
- server <- function (input , output ) {
191
+ app_env <- load_app_box()
192
+ ui <- function (request ) {
193
+ app_env $ main $ ui(" app" )
194
+ }
195
+ server <- function (input , output , session ) {
203
196
app_env $ main $ server(" app" )
204
197
}
205
198
shiny :: shinyApp(
206
199
ui = with_head_tags(ui ),
207
- server = fix_server_reloading (server )
200
+ server = reparse (server )
208
201
)
209
202
} else {
210
203
stop()
0 commit comments