【问题标题】:R shiny application for CI用于 CI 的 R 闪亮应用
【发布时间】: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()
  })
})

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    欢迎来到 SO,并祝贺您提供了如此有据可查的示例。

    由于嵌套结构,Shiny 的错误消息难以理解,而且调试也很麻烦。您的代码中有一些“小”错误:

    • 消息来自 SliderInput("samplesize",...) 之后的逗号,此处需要另一个表达式。
    • 在 ui 中,data.frame() 之后应该多一个关闭 ")"
    • “s(S)amplesize”拼写不一致

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 1970-01-01
      • 2020-02-18
      • 2019-02-15
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      • 2021-02-16
      相关资源
      最近更新 更多