Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create multiple pages with its own set of widgets in Shiny

Tags:

r

shiny

I want to be able to create multiple pages each with a set of widgets drop down, radio button and a space to plot a map. The Shiny tutorial shows how to create multiple pages

shinyUI(navbarPage("My Application",
  tabPanel("Component 1"),
  tabPanel("Component 2"),
  tabPanel("Component 3")
))

How can I add widgets in each page for e.g. how can I add the following to Component 1?

  sidebarLayout(
    sidebarPanel(
        selectizeInput(
            'id', label = "Year", choices =   NULL,multiple=FALSE,selected="X2015",
            options = list(create = TRUE,placeholder = 'Choose the year')

        ),
        # Make a list of checkboxes
        radioButtons("radio", label = h3("Radio buttons"),
                     choices = list("Choice 1" = 1,
                                   "Choice 2" = 2)

and

     mainPanel(
        plotOutput("distPlot")
    )
like image 465
Tinniam V. Ganesh Avatar asked Oct 13 '15 16:10

Tinniam V. Ganesh


2 Answers

You should probably read the reference page of tabPanel: http://shiny.rstudio.com/reference/shiny/latest/tabPanel.html

shinyUI(
    navbarPage("My Application",
             tabPanel(
               "Component 1",
               sidebarLayout(
                 sidebarPanel(
                   selectizeInput(
                     'id', label="Year", choices=NULL, multiple=F, selected="X2015",
                     options = list(create = TRUE,placeholder = 'Choose the year')
                   ),
                   # Make a list of checkboxes
                   radioButtons("radio", label = h3("Radio buttons"),
                                choices = list("Choice 1" = 1, "Choice 2" = 2)
                   )
                 ),
                 mainPanel( plotOutput("distPlot") )
               )
             ),
             tabPanel("Component 2"),
             tabPanel("Component 3")
  )
)
like image 131
user5029763 Avatar answered Oct 03 '22 02:10

user5029763


You could do tabPanel("Component 1", ...), replacing the dots with all of your sidebarPanel code. Or, use renderUI on the server side,

library(shiny)

shinyApp(
    shinyUI(
        navbarPage("My Application",
                   tabPanel("Component 1", uiOutput('page1')),
                   tabPanel("Component 2"),
                   tabPanel("Component 3")
                   )
    ),
    shinyServer(function(input, output, session) {
        output$page1 <- renderUI({
            sidebarLayout(
                sidebarPanel(
                    selectizeInput(
                        'id', label = "Year", choices =   NULL,multiple=FALSE,selected="X2015",
                        options = list(create = TRUE,placeholder = 'Choose the year')
                    ),
                    ## Make a list of checkboxes
                    radioButtons("radio", label = h3("Radio buttons"),
                                 choices = list("Choice 1" = 1, "Choice 2" = 2))
                ),
                mainPanel(
                    plotOutput('distPlot')
                )
            )
        })

        output$distPlot <- renderPlot({ plot(1) })
    })
)
like image 27
Rorschach Avatar answered Oct 03 '22 03:10

Rorschach