如何在R语言Shiny框架中使用fluidRow及修正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
相关产品推荐
相关产品推荐

