shiny - 添加单个复选框输入
问题描述
我正在寻找一种添加复选框输入的方法,它应该在勾选时显示此数据集的等待时间和中断。我是 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 或字符向量
解决方案
问题是您当前将三个参数传递给 function sidebarLayout
,尽管只需要两个参数。问题中的 ui 定义如下所示
fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput(...)
),
checkboxInput(...),
mainPanel(
plotOutput(...)
)
)
)
(我用作...
占位符以使代码更具可读性。)checkboxInput
应该放在任何一个面板中。例如
fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput(...),
checkboxInput(...)
),
mainPanel(
plotOutput(...)
)
)
)
推荐阅读
- javascript - 将替换方法的组合转换为一个
- ruby-on-rails - 如何使用 Proc.new
- python - 尝试使用 join/split 删除我自己的停用词
- python - 从包含索引的另一个子列表的子列表中获取项目
- javascript - 使用 Sequelize 破坏模型的麻烦
- batch-file - SVN 和 JIRA 集成以使用 API 检查 JIRA 中是否存在问题
- sql - SQL 全外连接 + group by + count 列
- android - 当在 Tabs 中再次打开 Fragment 时,Recycler View 变为空视图
- c# - 调试 ASP.NET (.NET Framework 4.8) Web 应用程序时,没有为新 csproj 格式的 (.NET Framework 4.8) 库加载符号
- php - PHP Null 合并混乱