Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny with multiple tabs and different sidebar in each tab

Tags:

tabs

r

shiny

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 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))   
                )
            )
        )
    )
)
like image 388
Sazan Abdalrhman Avatar asked May 28 '17 00:05

Sazan Abdalrhman


1 Answers

I made a simple UI template you can use based on your description. I also changed your column specification from 8,7 to 7,5 because shiny UI is based on 12 grid system. 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) {

  }
)
like image 151
dvarelas Avatar answered Sep 23 '22 07:09

dvarelas