Shiny with multiple tabs and a different sidebar on each tab

I am trying to have multiple tabs, each tab with its own sidebar, I need selectInput

in the first tab and sliderInput

in the second tab.

Can anyone please help?

My code:

ui <- fluidPage(

    headerPanel("Terrorism in The World"),
            sidebarPanel(      
                    selectInput("Country", "Select Country", choices = sort(unique(mydat$Country)), selected = "Iraq")
                ,sliderInput("year", "Year:", min = 1968, max = 2009, value = 2009, sep='')
        ),
        mainPanel(

        tabsetPanel(
            tabPanel("Map",htmlOutput("Attacks")),
            tabPanel("plot",
                fluidRow(
                    column(8,  plotlyOutput("trendheatrPlot", height = "300px",width = 700)),
                    column(7, plotlyOutput("trendstakbarPlot", height = "300px",width = 700))   
                )
            )
        )
    )
)

      

+3


source to share


1 answer


I created a simple UI template that you can use based on your description. I also changed the column spec from 8.7 to 7.5 because the shiny interface is based on 12 grid systems. Here is the code:



library(shiny)
library(plotly)

shinyApp(
  ui = fluidPage(
    tabsetPanel(
      tabPanel("Map", fluid = TRUE,
               sidebarLayout(
                 sidebarPanel(selectInput("Country", "Select Country", choices = "", selected = "")),
                 mainPanel(
                   htmlOutput("Attacks")
                 )
               )
      ),
      tabPanel("plot", fluid = TRUE,
               sidebarLayout(
                 sidebarPanel(sliderInput("year", "Year:", min = 1968, max = 2009, value = 2009, sep='')),
                 mainPanel(fluidRow(
                   column(7,  plotlyOutput("")),
                   column(5, plotlyOutput(""))   
                 )
                 )
               )
      )
    )
  ), 
  server = function(input, output) {

  }
)

      

+9


source







All Articles