【发布时间】:2014-12-08 08:07:48
【问题描述】:
我正在尝试构建我的第一个 R Shiny 应用程序。我想建立一个置信区间模拟,其中侧面有滑块,当你改变一些东西(样本大小、置信水平、标准差或平均值)时,置信区间长度的图会随着反应而变化。我从 Shiny 网站上拿了一个滑块示例,并尝试更改,但它不起作用。经过一些小的更改后,我收到消息“标签错误(“表单”,列表(...)):参数丢失,没有默认值”。另外,我不知道如何制作一个漂亮的置信区间图,中间是平均值,你能帮忙吗? 我当前的代码是:
library(shiny)
# Define UI for slider demo application
shinyUI(fluidPage(
# Application title
titlePanel("Confidence Interval for the mean when sigma is known"),
# Sidebar with sliders that demonstrate various available
# options
sidebarLayout(
sidebarPanel(
# Simple integer interval
sliderInput("mean", "Mean:",
min=0, max=500, value=250),
# Decimal interval with step value
sliderInput("confidence", "Confidence level:",
min = 0, max = 1, value = 0.95, step= 0.01),
# Specification of range within an interval
sliderInput("sigma", "Standard deviation:",
min = 0, max = 300, value = 10),
# Provide a custom currency format for value display,
# with basic animation
sliderInput("Samplesize", "Sample size:",
min = 0, max = 1000, value = 30, step = 1),
),
# Show a table summarizing the values entered
mainPanel(
tableOutput("values")
)
)
))
和
library(shiny)
# Define server logic for slider examples
shinyServer(function(input, output) {
# Reactive expression to compose a data frame containing all of
# the values
sliderValues <- reactive({
# Compose data frame
data.frame(
Name = c("Mean",
"Confidence Interval",
"Standard Deviation",
"Sample size"),
Value = as.character(c(input$mean,
input$confidence,
input$sigma,
input$samplesize),
stringsAsFactors=FALSE)
})
# Show the values using an HTML table
output$values <- renderTable({
sliderValues()
})
})
【问题讨论】: