2014-10-10 58 views
3

我想在我的RShiny應用程序的選項卡中顯示多個輸出對象。在本教程中tabPanel(...)命令只參數:RShiny:顯示多個輸入和文本

tabPanel("Plot", plotOutput("plot")) 

然而,在參考文檔here,它讀取「UI元素小號到標籤中包括」導致我相信,多是可能的,但我找不到例子。我曾嘗試將對象傳遞給它作爲矢量c(...)和列表list(...)

這裏是server.Rui.R我一直在測試(來自Shiny Tutorial)。

ui.R


library(shiny) 

    # Define UI for random distribution application 
    shinyUI(fluidPage(

     # Application title 
     titlePanel("Tabsets"), 

     # Sidebar with controls to select the random distribution type 
     # and number of observations to generate. Note the use of the 
     # br() element to introduce extra vertical spacing 
     sidebarLayout(
     sidebarPanel(
      radioButtons("dist", "Distribution type:", 
         c("Normal" = "norm", 
         "Uniform" = "unif", 
         "Log-normal" = "lnorm", 
         "Exponential" = "exp")), 
      br(), 

      sliderInput("n", 
         "Number of observations:", 
         value = 500, 
         min = 1, 
         max = 1000) 
     ), 

     # Show a tabset that includes a plot, summary, and table view 
     # of the generated distribution 
     mainPanel(
      tabsetPanel(type = "tabs", 
         tabPanel("Plot", plotOutput("plot")), 
         tabPanel("Summary", verbatimTextOutput("summary")), 
         tabPanel("Table", tableOutput("table")) 
     ) 
     ) 
    ) 
    )) 

server.R


library(shiny) 

    # Define server logic for random distribution application 
    shinyServer(function(input, output) { 

     # Reactive expression to generate the requested distribution. 
     # This is called whenever the inputs change. The output 
     # functions defined below then all use the value computed from 
     # this expression 
     data <- reactive({ 
     dist <- switch(input$dist, 
         norm = rnorm, 
         unif = runif, 
         lnorm = rlnorm, 
         exp = rexp, 
         rnorm) 

     dist(input$n) 
     }) 

     # Generate a plot of the data. Also uses the inputs to build 
     # the plot label. Note that the dependencies on both the inputs 
     # and the data reactive expression are both tracked, and 
     # all expressions are called in the sequence implied by the 
     # dependency graph 
     output$plot <- renderPlot({ 
     dist <- input$dist 
     n <- input$n 

     hist(data(), 
      main=paste('r', dist, '(', n, ')', sep='')) 
     }) 

     # Generate a summary of the data 
     output$summary <- renderPrint({ 
     summary(data()) 
     }) 

     # Generate an HTML table view of the data 
     output$table <- renderTable({ 
     data.frame(x=data()) 
     }) 

    }) 
+2

幫助頁面上的用法節建議「UI元素到標籤中包括」 'c()'和'list()'都不合適。省略號應該採取任意數量的「解包」參數。 – 2014-10-10 21:12:17

回答

3

以下爲我工作:

mainPanel(
    tabsetPanel(
     tabPanel("Some Title", 
       h5(textOutput("some text output")), 
       htmlOutput("someHTMLElement") 
    ), 
     tabPanel("Other Title", 
       h5(textOutput("some other text output")), 
       htmlOutput("otherHTMLElement") 
    ), 
     tabPanel("Yet Another Title", 
       h5(textOutput("yet another text output")), 
       htmlOutput("yetAnotherHTMLElement") 
    ) 
    ) 

功能tabPanel規範是

tabPanel(title, ..., value = NULL) 

這意味着它接受可變數量的用於參數