RShiny:显示多个输入和文本 [英] RShiny: Display Multiple Inputs and Text
问题描述
我想在我的 RShiny 应用程序的选项卡内显示多个输出对象.在教程中 tabPanel(...)
命令只接受参数:
I would like to display multiple output objects inside a tab in my RShiny app. In the tutorial the tabPanel(...)
command only takes argument:
tabPanel("Plot", plotOutput("plot"))
但是在参考文档这里中,它读作UI 元素s 包含在选项卡中" 让我相信多个是可能的,但我找不到示例.我尝试将对象作为向量 c(...)
和列表 list(...)
传递给它.
However in the reference docs here, it reads "UI elements to include within the tab" leading me to believe that multiple are possible, but I cannot find examples. I have attempted passing objects to it as a vector c(...)
and a list list(...)
.
这是我一直在测试的 server.R
和 ui.R
(来自 Shiny 教程).
Here are the server.R
and ui.R
I have been testing with (from the 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())
})
})
推荐答案
以下对我有用:
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)
这意味着它接受可变数量的参数,用于要包含在选项卡中的 UI 元素"
which means that it accepts variable number of parameters for "UI elements to include within the tab"
这篇关于RShiny:显示多个输入和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!