You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R语言Shiny框架中使用fluidRow及修正radioButtons参数

Shiny中radioButtons参数的正确配置方法

你的代码里radioButtons函数的核心错误是choices参数没有以向量形式传递,Shiny要求这个参数必须是用c()包裹的字符向量,同时还存在一处拼写错误("Continuos"应该改为"Continuous"),以下是修正后的完整布局代码:

# Application Layout
shinyUI(
  fluidPage(
    br(),
    titlePanel("Country Salary"),
    p("Explore the difference between people who earn less than 50K and more than 50K. You can filter the data by country, then explore various demogrphic information."),
    
    # TASK 2: Add first fluidRow to select input for country
    fluidRow(
      column(12, 
             wellPanel(selectInput("country", "Select Country",c("United-States", "Canada", "Mexico", "Germany", "Philippines"))  # add select input 
             )
    ),
    
    # TASK 3: Add second fluidRow to control how to plot the continuous variables
    fluidRow(
      column(3, 
             wellPanel(
               p("Select a continuous variable and graph type (histogram or boxplot) to view on the right."),
               # 修正choices为向量形式,同时修正拼写错误
               radioButtons("continuous_variable","Continuous variable",choices = c("age", "hours_per_week")),   
               radioButtons("graph_type","Graph", choices = c("histogram","boxplot"))    
               )
             ),
      column(9, plotOutput("P1"))  # add plot output
    )
  )
)

关键修正说明:

  • 所有radioButtons的choices参数都用c()将多个选项包裹成向量,这是Shiny输入控件的必填格式
  • 修正了标签里的拼写错误:"Continuos variable"改为"Continuous variable"
  • 补充了原代码中缺失的fluidRow和fluidPage闭合括号(原代码末尾少了两个))

内容的提问来源于stack exchange,提问作者H.C

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 16:36:06