Hi there,
I am trying to build a shiny web app consisting of multiple pages. I want the app to open a certain page if any of a number of different actionButtons are pressed.
I build an example of the structure (see below). Page 2 should be loaded if either B1
or B2
are pressed.
I used | as an operator to include the different inputs, however I run into the problem that R loads page 2 right away instead of page 1. If you seperate the inputs by , R returns the error env
must be an environment.
Please note that in the actual application I want to include >2 inputs.
Any help or hint how to solve this would be greatly appreciated!
Thanks a lot
library(shiny)
ui <- (htmlOutput("page"))
Page1 <- function(...) {
div(class = 'container', id = "Page1",
actionButton("B1", "B1"),
actionButton("B2", "B2")
)}
Page2 <- function(...) {
div(class = 'container', id = "Page2",
actionButton("B3", "B3")
)}
render_page <- function(...,f, title = "Test") {
page <- f(...)
renderUI({
fluidPage(page, title = title)
})
}
server <- function(input, output) {
output$page <- render_page(f = Page1)
observeEvent(input$B1 | input$B2,
{output$page <- render_page(f = Page2)
})
}
shinyApp(ui = ui, server = server)