添加一个复选框输入

时间:2019-04-05 17:16:45

标签: shiny rstudio

我正在寻找一种添加checkboxInput的方法,当勾选时,它应该显示此数据集的等待时间和中断。 我是rstudio的一名新手,不知道我在做什么。 该程序的代码是:

#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)

library(tidyverse)
# Define UI for application that draws a histogram
ui <- fluidPage(

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),

      checkboxInput("checkbox", label = "Choice A", value = TRUE),
      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

到目前为止,在运行代码并尝试对其进行修复后,我仅遇到相同的错误。 match.arg(position)中的错误:“ arg”必须为NULL或字符向量

1 个答案:

答案 0 :(得分:0)

问题在于,当前您将三个参数传递给函数sidebarLayout,尽管仅期望两个参数。问题中的ui定义如下

fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput(...)
    ),
    checkboxInput(...),
    mainPanel(
      plotOutput(...)
    )
  )
)

(我使用...作为占位符以使代码更具可读性。)checkboxInput应该放在两个面板中。例如

fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput(...),
      checkboxInput(...)
    ),
    mainPanel(
      plotOutput(...)
    )
  )
)