Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- options(shiny.reactlog = TRUE)
- library(shiny)
- library(reactlog)
- mod_iris_ui <- function(id) {
- ns <- NS(id)
- tagList(
- fluidRow(
- column(
- 2,
- selectInput(
- inputId = ns("species"),
- label = "species",
- choices = list(
- "loading..." = 1
- ),
- selected = 1
- )
- ),
- column(
- 10,
- plotOutput(ns("speciesplot"))
- )
- )
- )
- }
- mod_iris <- function(input, output, session) {
- ns <- session$ns
- df <- reactive({
- req(ns(input$open_tab) == "iris")
- df <- iris
- })
- observe({
- req(ns(input$open_tab) == "iris")
- values <- as.character(unique(df()[["Species"]]))
- updateSelectInput(session, "species",
- choices = values,
- selected = values[1]
- )
- })
- output$speciesplot <- renderPlot({
- hist(iris[iris$Species == input$species, 1])
- })
- }
- mod_mtcars_ui <- function(id) {
- ns <- NS(id)
- tagList(
- fluidRow(
- column(
- 2,
- selectInput(
- inputId = ns("gear"),
- label = "gear",
- choices = list(
- "loading..." = 1
- ),
- selected = 1
- )
- ),
- column(
- 10,
- plotOutput(ns("gearplot"))
- )
- )
- )
- }
- mod_mtcars <- function(input, output, session) {
- ns <- session$ns
- df <- reactive({
- req(ns(input$open_tab) == "mtcars")
- df <- mtcars
- })
- observe({
- req(ns(input$open_tab) == "mtcars")
- values <- unique(df()[["gear"]])
- updateSelectInput(session, "gear",
- choices = values,
- selected = values[1]
- )
- })
- output$gearplot <- renderPlot({
- hist(mtcars[mtcars$gear == input$gear, 1])
- })
- }
- ui <- tagList(
- navbarPage(
- title = "App",
- id = "open_tab",
- tabPanel(
- "iris",
- mod_iris_ui("iris")
- ),
- tabPanel(
- "mtcars",
- mod_mtcars_ui("mtcars")
- )
- )
- )
- server <- function(input, output, session) {
- callModule(
- mod_iris,
- "iris"
- )
- callModule(
- mod_mtcars,
- "mtcars"
- )
- }
- shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement