我一直试图让我的第一个Shiny App工作,但是我收到一条错误,上面写着“错误:参数”mainPanel“缺失,没有默认值”
我不知道该怎么做。
ui.R:
library(shiny)
shinyUI(fluidPage(
titlePanel(title = h4("Katrina Data Shiny Application - a histogram", align = "center")),
sidebarLayout(
sidebarPanel(
selectInput("var",
"1. Select the variable from the katrina dataset",
choices = c("flood depth", "log_medinc"),
selected = "flood_depth"),
sliderInput("bins",
"2. Select the number of bins for the histogram",
min=5,
max=50,
value=15
)
)
),
mainPanel(
plotOutput("myhist"))
)
)
我的Server.R:
library(shiny)
shinyServer(
function(input, output) {
katrina = read.csv("katrina.csv")
output$myhist <- renderPlot ({
data <- switch(input$var,
"flood depth" = katrina$flood_depth,
"log_medinc" = katrina$log_medinc)
color <- switch(input$var,
"flood depth" = "darkgreen",
"log_medinc" = "deepskyblue"),
legend <- switch(input$var,
"flood depth" = "flood depth",
"log_medinc" = "log_medinc")
hist(var = data, color = color, l=input$bins+1, legend.title = legend)
})
}
)
答案 0 :(得分:0)
Google搜索错误会将我引导至the following SO question。问题是mainPanel
应该在sideBarLayout
内调用。随便看一下,看起来你这样做,但仔细检查括号后发现你实际上并没有。正确的ui.R
应为:
shinyUI(fluidPage(
titlePanel(title = h4("Katrina Data Shiny Application - a histogram", align = "center")),
sidebarLayout(
sidebarPanel(
selectInput("var",
"1. Select the variable from the katrina dataset",
choices = c("flood depth", "log_medinc"),
selected = "flood_depth"),
sliderInput("bins",
"2. Select the number of bins for the histogram",
min=5,
max=50,
value=15
)
),
mainPanel(
plotOutput("myhist")
)
)
)
)