library(shiny) ui <- fluidPage( h1("Cars Data"), sidebarLayout( sidebarPanel( fluidRow( column( width = 12, uiOutput("bin_selector_ui"), uiOutput("column_selector_ui"), "MT Cars Data from R" ) ) ), mainPanel( plotOutput("histogram_plot"), plotOutput("scatter_plot") ) ) ) server <- function(input, output, session) { RV = reactiveValues( data_df = mtcars ) output$bin_selector_ui = renderUI({ sliderInput("bin_selector", "Number of bins:", min = 0, max = 50, value = 30) }) output$column_selector_ui = renderUI({ selectInput("column_selector", "Choice:", choices = colnames(req(RV$data_df[,-1]))) }) output$histogram_plot = renderPlot({ data_df <- req(RV$data_df) bins <- req(input$bin_selector) hist(data_df$mpg, breaks = bins) }) output$scatter_plot = renderPlot({ data_df <- req(RV$data_df) selected_column <- req(input$column_selector) data_df = data_df[, c(selected_column, "mpg")] plot(data_df) }) } shinyApp(ui, server)