R shiny code suggestion

I would like to build a Shiny app with the following template:

  • The app has a left and right panels
  • When the app is launched, only a left panel is visible. The user is allowed to pick some data series to display from a list of choices.
  • Once the user has made the selection and hit submit, the outputs are shown in the right panel.

I have been working on it but have run into difficulties getting the code to work. If anyone could suggest to me a similar app with code I can look at, I would appreciate it. Thanks!

Not exactly an app in the wild, but the 3rd pattern here seems to be exactly what you want.

By now, the documentation recommends replacing observeEvent() with bindEvent(), which also has nice ignoreNULL and ignoreInit options (see the manpage for details), so something like that should do what you want:

library(shiny)
library(tidyverse)

dat1 <- data.frame(x = 1:3,
                   y = 5:7)
dat2 <- data.frame(x = 1:3,
                   y = 7:5)

accepted_data <- c("dat1", "dat2")


ui <- fluidPage(
  
  sidebarLayout(
    sidebarPanel(
      selectInput("dataSelect", "Select data", accepted_data),
      actionButton("submitButton", "Submit")
    ),
    mainPanel(
      plotOutput("myPlot"),
      width = 3
    )
  )
)


server <- function(input, output, session) {
  
  mydata <- bindEvent(reactive(eval(as.name(input$dataSelect))),
                      input$submitButton,
                      ignoreInit = TRUE)
  
  output$myPlot <- renderPlot({
    ggplot(mydata()) + 
      geom_point(aes(x,y))
  })
}

shinyApp(ui = ui, server = server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.