每个标签中都有多个标签和不同侧边栏

时间:2017-05-28 00:41:57

标签: r tabs shiny

我正在尝试使用多个标签,每个标签都有自己的侧边栏,第一个标签中需要selectInput,第二个标签需要sliderInput

有人可以帮忙吗?

我的代码:

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))   
                )
            )
        )
    )
)

1 个答案:

答案 0 :(得分:19)

我根据您的描述创建了一个简单的UI模板。我还将列规范从8,7改为7,5,因为闪亮的UI基于12个网格系统。这是代码:

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) {

  }
)