-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.R
87 lines (61 loc) · 2.08 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
### Keep this line to manually test this shiny application. Do not edit this line; shinycoreci::::is_manual_app
library(shiny)
# Define UI for app that draws a histogram ----
ui <- fluidPage(
# App title ----
titlePanel("Hello Shiny!"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Slider for the number of bins ----
sliderInput(inputId = "bins",
label = "Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
plotOutput(outputId = "distPlot")
)
),
# include shinyjster JS at end of UI definition
shinyjster::shinyjster_js("
var jst = jster();
jst.add(Jster.shiny.waitUntilStable);
jst.add(Jster.shiny.waitUntilIdleFor(1000));
var img30;
jst.add(function(){
Jster.assert.isEqual(Jster.slider.getValue('bins'), 30);
// convert to character string
img30 = JSON.stringify(Jster.image.data('distPlot'));
Jster.slider.setValue('bins',10);
});
jst.add(Jster.shiny.waitUntilStable);
jst.add(Jster.shiny.waitUntilIdleFor(1000));
jst.add(function(){
Jster.assert.isEqual(Jster.slider.getValue('bins'), 10);
var img10 = JSON.stringify(Jster.image.data('distPlot'));
Jster.assert.isTrue(img30 !== img10, {xbins: 30, ybins: 10});
});
jst.test();
")
)
# Define server logic required to draw a histogram ----
server <- function(input, output, session) {
# include shinyjster_server call at top of server definition
shinyjster::shinyjster_server(input, output)
x <- faithful$waiting
bins <- reactive({
seq(min(x), max(x), length.out = input$bins + 1)
})
output$distPlot <- renderPlot({
hist(x, breaks = bins(), col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)