【问题标题】:selectInput in R shinyR中的selectInput闪亮
【发布时间】:2015-05-07 14:17:53
【问题描述】:

我想从 Mysql 查询中读取的列表中进行选择。我在代码中遇到错误。我一定是做错了什么,但不确定是什么。

我想从从 sql 查询中读取的 skus 列表中进行选择。我在 ui 部分收到错误。

我什至不确定这是否可能,但列出所有 sku 将非常及时。

我收到以下错误:

标签错误("div", list(...)) : 缺少参数“sidebarPanel”,没有默认值

shinyApp(ui = ui, 服务器 = 服务器) force(ui) 中的错误:找不到对象“ui”

library('RMySQL')
library('plyr')
library('shiny')
library('scales')
library(shinyapps)
library(ggplot2)



con <- dbConnect(MySQL(), user="user", password="password",dbname="DB", host="host");


rank<-dbGetQuery(con,"select sku from DB")




#build a shiny app to select which sku to pick
server <- function(input, output) {

  output$distPlot <- renderPlot({
    hist(rnorm(input$obs), col = 'darkgray', border = 'white')
  })
}

ui <- pageWithSidebar(
  ## Application title

    sidebarPanel(
      sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100),
      selectInput(
        'e0', '0. An ordinary select input', choices = unique(rank$sku),
        selectize = FALSE
      ),

      mainPanel(plotOutput("distPlot"))

  )

)

shinyApp(ui = ui, server = server)

【问题讨论】:

  • 您遇到什么错误? (收到错误后,您能否也发布traceback() 的结果?
  • 标签错误(“div”,列表(...)):缺少参数“sidebarPanel”,没有默认值>>shinyApp(ui = ui,server = server)强制错误( ui) : 找不到对象 'ui'
  • pageWithSidebar 需要一个 headerPanel 作为第一个参数。在sidebarPanel( 行之前添加headerPanel("Some Title"),

标签: mysql r user-interface shiny


【解决方案1】:

您的selectize = FALSE 附近有一个缺少括号,并且(正如@DavidRobinson 建议的那样)您需要一个headerPanel

代码修复

library(shiny)
library(ggplot2)
# con <- dbConnect(MySQL(), user="user", password="password",dbname="DB", host="host");
# rank<-dbGetQuery(con,"select sku from DB")
# for test hard coding the rank as I dont have your data
# test rank
rank$sku <- c(1,2,3)

#build a shiny app to select which sku to pick
server <- function(input, output) {
  output$distPlot <- renderPlot({
    hist(rnorm(input$obs), col = 'darkgray', border = 'white')
  })
}

ui <- pageWithSidebar(
  ## Application title

  # missing headerPanel
  headerPanel(title = "Hello"),

  # missing bracket after selectize
  sidebarPanel(
    sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100),
    selectInput(
      'e0', '0. An ordinary select input', choices = unique(rank$sku),
      selectize = FALSE) 
    ),

  mainPanel(plotOutput("distPlot"))    
)

shinyApp(ui = ui, server = server)

结果

另一个闪亮的页面用户界面选项

您也可以使用标签页结构,将上面的ui 替换为这段代码(注意它不需要像上面那样的headerPanel):

# navbar tabbed page example - without headerPanel
ui2 <- navbarPage(title = "Hello Another Style", 
           tabPanel("Chart Panel",
                    sidebarLayout(
                      sidebarPanel(
                        sliderInput("obs", "Number of observations:", 
                                    min = 10, max = 500, value = 100),
                        selectInput(
                          'e0', '0. An ordinary select input', 
                          choices = unique(rank$sku),
                          selectize = FALSE)
                        ),
                      mainPanel(
                        plotOutput("distPlot")
                      )
                    )
           ),
           tabPanel("Instructions",
                    mainPanel(
                       p("Notes here for example...")
                    )
           )        

)

第二个结果

然后在第二个面板上...

调试建议

这些Shiny 页面可能有很多括号,因此在编辑器中依次仔细选择括号,以确保括号匹配正确。

一切顺利!

【讨论】:

  • @megv,同时更新你的 RStudio! 0.99 链通过自动完成改进了编辑器,因此您不会再遭受这种痛苦 - release notes“对于闪亮的应用程序,ui.R + server.R 对的自动完成”。
猜你喜欢
  • 2016-07-28
  • 2018-07-09
  • 1970-01-01
  • 2018-07-25
  • 2016-08-12
  • 2018-09-21
  • 1970-01-01
  • 2021-01-04
  • 2019-01-24
相关资源
最近更新 更多