首页 > 解决方案 > 缺少参数“mainPanel”,R 闪亮中没有默认值

问题描述

我对 Shiny R 还很陌生!我想我可能缺少括号,但我一直在检查,但找不到错误。抱歉发布这么多代码!但是,如果你们可以检查我可能缺少括号的位置,是否有可能?

ui <- fluidPage(
  navbarPage(title = "Demo Bar",
             tabPanel("Percent college",
                      sidebarLayout(
                        sidebarPanel(
                          selectInput(inputId = "state", label = "Select a state:",
                                      choices = unique(midwest$state),
                                      selected = "IL",
                                      multiple = TRUE),
                          hr(),
                          helpText("Data From Midwest data frame"),
                          textInput(inputId = "title", label = "Write a title!", value = "Midwest scatter plot comparison"),
                        ),
                        mainPanel(
                          plotlyOutput("scatterplot")
                      ),
             ),
             ),
             tabPanel("Data Page",
                sidebarLayout(
                  sidebarPanel(
                    sliderInput(
                      inputId = "area_choice",
                      label = "Range of Area",
                      min = area_range[1],
                      max = area_range[2],
                      value = area_range
                    ),
                    mainPanel(
                      plotOutput("plot")
                  ),
                ),
             ),
             ),
),
)


             
            

标签: rshinyshinyapps

解决方案


  1. 正如斯蒂芬所评论的那样,你mainPanel放错地方了
  2. 您有几个逗号没有进一步输入,这在 R 中可能会出现问题

另请注意,我必须添加area_rangelibrary调用。您的示例无法直接重现

library(shiny)
library(plotly)
area_range <- c(1,2)

ui <- fluidPage(
  navbarPage(title = "Demo Bar",
             tabPanel("Percent college",
                      sidebarLayout(
                        sidebarPanel(
                          selectInput(inputId = "state", label = "Select a state:",
                                      choices = unique(midwest$state),
                                      selected = "IL",
                                      multiple = TRUE),
                          hr(),
                          helpText("Data From Midwest data frame"),
                          textInput(inputId = "title", label = "Write a title!", value = "Midwest scatter plot comparison"),
                        ),
                        mainPanel(
                          plotlyOutput("scatterplot")
                        )
                      )
             ),
             tabPanel("Data Page",
                      sidebarLayout(
                        sidebarPanel(
                          sliderInput(
                            inputId = "area_choice",
                            label = "Range of Area",
                            min = area_range[1],
                            max = area_range[2],
                            value = area_range
                          ),
                        ),
                        mainPanel(
                          plotOutput("plot")
                        )
                      )
             )
  )
)

shinyApp(ui, function(input, output) {})

推荐阅读