forked from ameliaritger/mbon-shiny-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-gallery.R
48 lines (35 loc) · 999 Bytes
/
image-gallery.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
library(shiny)
folder <- "C:/Users/Amelia/github/shiny-app-mbon/www/"
imgs <- list.files(path=folder, pattern=".jpg", full.names = TRUE)
ui <- fluidPage(
titlePanel("Slideshow"),
sidebarLayout(
sidebarPanel(
# actionButton("previous", "Previous"),
# actionButton("next", "Next")
),
mainPanel(
imageOutput("image"),
fluidRow(
column(1, offset=1, actionButton("previous", "Previous")),
column(1, offset=1, actionButton("next", "Next"))
)
)
)
)
server <- function(input, output, session) {
index <- reactiveVal(1)
observeEvent(input[["previous"]], {
index(max(index()-1, 1))
})
observeEvent(input[["next"]], {
index(min(index()+1, length(imgs)))
})
outfile <- tempfile(fileext = '.png')
output$image <- renderImage({
x <- imgs[index()]
list(src = x, alt = "alternate text", height = "50%")
}, deleteFile = FALSE)
}
# Run the application
shinyApp(ui = ui, server = server)