forked from daattali/advanced-shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
40 lines (33 loc) · 798 Bytes
/
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
library(shiny)
library(shinyjs)
NUM_PAGES <- 5
ui <- fluidPage(
useShinyjs(),
hidden(
lapply(seq(NUM_PAGES), function(i) {
div(
class = "page",
id = paste0("step", i),
"Step", i
)
})
),
br(),
actionButton("prevBtn", "< Previous"),
actionButton("nextBtn", "Next >")
)
server <- function(input, output, session) {
rv <- reactiveValues(page = 1)
observe({
toggleState(id = "prevBtn", condition = rv$page > 1)
toggleState(id = "nextBtn", condition = rv$page < NUM_PAGES)
hide(selector = ".page")
show(paste0("step", rv$page))
})
navPage <- function(direction) {
rv$page <- rv$page + direction
}
observeEvent(input$prevBtn, navPage(-1))
observeEvent(input$nextBtn, navPage(1))
}
shinyApp(ui, server)