我想从一个从Mysql查询中读入的列表中进行选择。我在代码中收到错误。我必须做一些完全错误的事情,但不确定是什么。
我想从sql查询中读入的skus列表中进行选择。我在ui部分出错了。
我甚至不确定这是否可行,但列出所有skus将非常及时。
我收到以下错误:
标记错误(" div",list(...)): 参数" sidebarPanel"缺少,没有默认
shinyApp(ui = ui,server = server) 生效错误(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)
答案 0 :(得分:2)
您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)
<强> RESULT 强>
另一个SHINY PAGE UI选项
您也可以使用选项卡式页面结构,将上面的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
页面可以包含很多括号,因此在您的代码中依次选择括号,在编辑器中依次选择括号,例如RStudio,以确保括号匹配正常。
一切顺利!