1 |
#' Run example app
|
|
2 |
#'
|
|
3 |
#' @return A shiny app object
|
|
4 |
#' @export
|
|
5 |
#' @import shiny
|
|
6 |
run_app <- function() { |
|
7 |
# serve js tools for Monkey test (in case proxy blocks external scripts)
|
|
8 | ! |
addResourcePath("gremlins", "inst/shinyValidator-js") |
9 |
# DON'T CHANGE (INTERNAL TO SHINYVALIDATOR)
|
|
10 | ! |
if (!exists(".enable_reactlog")) .enable_reactlog <- FALSE |
11 | ! |
if (!exists(".profile_code")) .profile_code <- FALSE |
12 | ||
13 | ! |
if (.enable_reactlog || .profile_code) { |
14 | ! |
tmp <- body(app_server) |
15 | ! |
start <- length(tmp) + 1 # start just before the closing } |
16 | ! |
body(app_server)[[start]] <- substitute( |
17 | ! |
onSessionEnded(function() { |
18 | ! |
stopApp(reactlog()) |
19 |
}) |
|
20 |
)
|
|
21 |
}
|
|
22 | ||
23 | ! |
runApp(shinyApp(app_ui, app_server), test.mode = TRUE) |
24 |
}
|
|
25 | ||
26 |
globalVariables(c("app_ui", "app_server")) |
1 |
#' The application server-side
|
|
2 |
#'
|
|
3 |
#' @param input,output,session Internal parameters for {shiny}. DO NOT REMOVE.
|
|
4 |
#' @import shiny
|
|
5 |
#' @import echarts4r
|
|
6 |
#' @noRd
|
|
7 |
app_server <- function(input, output, session) { |
|
8 |
# Your application server logic
|
|
9 | 1x |
output$echarts_plot <- renderEcharts4r({ |
10 | ! |
Sys.sleep(3) |
11 | ! |
make_echart(input$var) |
12 |
}) |
|
13 | ||
14 | 1x |
output$ggplot_plot <- renderPlot({ |
15 | ! |
make_ggplot(input$col) |
16 |
}) |
|
17 |
}
|
1 |
# "const customClicker = gremlins.species.clicker({
|
|
2 |
# // which mouse event types will be triggered
|
|
3 |
# clickTypes: ['click'],
|
|
4 |
# // Click only if element has id obs
|
|
5 |
# canClick: (element) => element.id === 'obs',
|
|
6 |
# // by default, the clicker gremlin shows its action by a red circle
|
|
7 |
# // overriding showAction() with an empty function makes the gremlin action invisible
|
|
8 |
# showAction: (x, y) => {},
|
|
9 |
# });
|
|
10 |
#
|
|
11 |
# gremlins.createHorde({
|
|
12 |
# randomizer: new gremlins.Chance(1234), // repeatable
|
|
13 |
# species: [customClicker],
|
|
14 |
# mogwais: [gremlins.mogwais.alert(),gremlins.mogwais.gizmo()],
|
|
15 |
# strategies: [
|
|
16 |
# gremlins.strategies.distribution({
|
|
17 |
# distribution: [1], // custom
|
|
18 |
# delay: 10 // default
|
|
19 |
# })
|
|
20 |
# ]
|
|
21 |
# }).unleash().then(() => {
|
|
22 |
# console.log('Gremlins test success')
|
|
23 |
# });"
|
|
24 | ||
25 |
echarts_df <- state.x77 %>% |
|
26 |
as.data.frame() %>% |
|
27 |
tibble::rownames_to_column("State") |
|
28 | ||
29 |
make_echart <- function(var) { |
|
30 |
# add the same id as plot output outside shiny
|
|
31 |
# to avoid random snapshot id issue
|
|
32 | ! |
id <- if (!shiny::isRunning()) "echarts_plot" else NULL |
33 | ! |
State <- NULL; |
34 | ! |
echarts_df %>% |
35 | ! |
e_charts(x = State, elementId = id) %>% # initialize and set x |
36 | ! |
e_line_(serie = var) # add a line |
37 |
}
|
|
38 | ||
39 |
#' @import ggplot2
|
|
40 |
make_ggplot <- function(var = "cyl") { # default to mpg |
|
41 | 1x |
ggplot(datasets::mtcars, aes_(x = as.name(var))) + geom_histogram(binwidth = 5) |
42 |
}
|
1 |
#' Access files in the current app
|
|
2 |
#'
|
|
3 |
#' NOTE: If you manually change your package name in the DESCRIPTION,
|
|
4 |
#' don't forget to change it here too, and in the config file.
|
|
5 |
#' For a safer name change mechanism, use the `golem::set_golem_name()` function.
|
|
6 |
#'
|
|
7 |
#' @param ... character vectors, specifying subdirectory and file(s)
|
|
8 |
#' within your package. The default, none, returns the root of the app.
|
|
9 |
#'
|
|
10 |
#' @noRd
|
|
11 |
app_sys <- function(...) { |
|
12 | ! |
system.file(..., package = "shinyValidatorTest2") |
13 |
}
|
|
14 | ||
15 | ||
16 |
#' Read App Config
|
|
17 |
#'
|
|
18 |
#' @param value Value to retrieve from the config file.
|
|
19 |
#' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE.
|
|
20 |
#' If unset, "default".
|
|
21 |
#' @param use_parent Logical, scan the parent directory for config file.
|
|
22 |
#'
|
|
23 |
#' @noRd
|
|
24 |
get_golem_config <- function( |
|
25 |
value,
|
|
26 |
config = Sys.getenv( |
|
27 |
"GOLEM_CONFIG_ACTIVE",
|
|
28 |
Sys.getenv( |
|
29 |
"R_CONFIG_ACTIVE",
|
|
30 |
"default"
|
|
31 |
)
|
|
32 |
),
|
|
33 |
use_parent = TRUE |
|
34 |
) { |
|
35 | ! |
config::get( |
36 | ! |
value = value, |
37 | ! |
config = config, |
38 |
# Modify this if your config file is somewhere else:
|
|
39 | ! |
file = app_sys("golem-config.yml"), |
40 | ! |
use_parent = use_parent |
41 |
)
|
|
42 |
}
|
1 |
#' The application User-Interface
|
|
2 |
#'
|
|
3 |
#' @param request Internal parameter for `{shiny}`.
|
|
4 |
#' DO NOT REMOVE.
|
|
5 |
#' @import shiny
|
|
6 |
#' @noRd
|
|
7 |
app_ui <- function(request) { |
|
8 | ! |
tagList( |
9 |
# Leave this function for adding external resources
|
|
10 | ! |
golem_add_external_resources(), |
11 |
# Your application UI logic
|
|
12 | ! |
fluidPage( |
13 | ! |
selectInput( |
14 | ! |
"var",
|
15 | ! |
"Select var",
|
16 | ! |
choices = colnames(echarts_df)[-1], |
17 | ! |
selected = "Population" |
18 |
),
|
|
19 | ! |
echarts4rOutput("echarts_plot"), |
20 | ! |
selectInput( |
21 | ! |
"col",
|
22 | ! |
"Select a column",
|
23 | ! |
choices = colnames(datasets::mtcars), |
24 | ! |
selected = "mpg" |
25 |
),
|
|
26 | ! |
plotOutput("ggplot_plot") |
27 |
)
|
|
28 |
)
|
|
29 |
}
|
|
30 | ||
31 |
#' Add external Resources to the Application
|
|
32 |
#'
|
|
33 |
#' This function is internally used to add external
|
|
34 |
#' resources inside the Shiny application.
|
|
35 |
#'
|
|
36 |
#' @import shiny
|
|
37 |
#' @importFrom golem add_resource_path activate_js favicon bundle_resources
|
|
38 |
#' @noRd
|
|
39 |
golem_add_external_resources <- function() { |
|
40 | ||
41 | ! |
add_resource_path( |
42 | ! |
"www", app_sys("app/www") |
43 |
)
|
|
44 | ||
45 | ! |
tags$head( |
46 | ! |
favicon(), |
47 | ! |
bundle_resources( |
48 | ! |
path = app_sys("app/www"), |
49 | ! |
app_title = "shinyValidatorTest2" |
50 |
)
|
|
51 |
# Add here other external resources
|
|
52 |
# for example, you can add shinyalert::useShinyalert()
|
|
53 |
)
|
|
54 |
}
|