R shiny 中 'closure' 类型的无效 'envir' 参数
invalid 'envir' argument of type 'closure' in R shiny
我正在 "invalid 'envir' argument of type 'closure'" 代替 R 闪亮仪表板中的图。无法找出错误。我正在尝试根据邮政编码的选择对数据进行子集化。如果有人能在这里提供帮助就太好了
library(shiny)
library(shinydashboard)
library(dplyr)
varsfilter = unique(final_kings_house_data$zipcode)
vars = unique(final_kings_house_data$zipcode)
if (interactive()) {
header <- dashboardHeader(title = "Kings County Housing Data")
sidebar <- dashboardSidebar(
sidebarSearchForm(label = "Enter a number", "searchText", "searchButton"),
sidebarMenu(
id = "tabs",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets", badgeLabel = "new",
badgeColor = "green"),
menuItem("Charts", icon = icon("bar-chart-o"),
menuSubItem("Trend Chart", tabName = "subitem1"),
menuSubItem("Scatter Plot", tabName = "subitem2")),
selectInput("filtervar", "Select zipcode", choices = vars),
checkboxGroupInput("filteroptions", "Select zipcode", choices = varsfilter)))
body <- dashboardBody(
tabItems(
tabItem("subitem1", fluidRow(
tabsetPanel(id = "tabselected",
tabPanel("Visualization", uiOutput("Tab1")),
tabPanel("Summary", uiOutput("Tab2"))))),
tabItem("widgets",
"Widgets tab content"),
tabItem("dashboard",
"Welcome!"),
tabItem("subitem2", fluidRow(
tabsetPanel(id = "tabselected",
tabPanel("Visualization", uiOutput("Tab3")),
tabPanel("Summary", uiOutput("Tab4"))
))
)))
shinyApp(
ui = dashboardPage(header, sidebar, body),
server = function(input, output,session) {
kings_house_data = reactive({
a = subset(final_kings_house_data, final_kings_house_data$zipcode == input$vars)
return(a)
})
view_aggregate = reactive({kings_house_data() %>% group_by(view) %>% summarise(price = mean(price))})
condition_aggregate = reactive({kings_house_data() %>% group_by(condition) %>% summarise(price = mean(price))})
floors_aggregate = reactive({kings_house_data() %>% group_by(floors) %>% summarise(price = mean(price))})
month_aggregate = reactive({kings_house_data() %>% group_by(month) %>% summarise(price = mean(price))})
output$Tab1 = renderUI({
mainPanel(fluidRow(
column(6,plotOutput(outputId = "viewplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "conditionplot", width="300px",height="300px"))),
fluidRow(
column(6,plotOutput(outputId = "floorsplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "monthplot", width="300px",height="300px"))))
})
output$Tab3 = renderUI({
mainPanel(fluidRow(
column(6,plotOutput(outputId = "view_scatterplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "condition_scatterplot", width="300px",height="300px"))),
fluidRow(
column(6,plotOutput(outputId = "floors_scatterplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "month_scatterplot", width="300px",height="300px"))))
})
output$viewplot = renderPlot({ plot(price/1000 ~ view , data = view_aggregate,
title = "Avg Price Vs View", xlab = "View", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$conditionplot = renderPlot({ plot(price/1000 ~ condition, data = condition_aggregate,
title = "Avg Price Vs Condition", xlab = "Condition", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$floorsplot = renderPlot({ plot(price/1000 ~ floors, data = floors_aggregate,
title = "Avg Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$monthplot = renderPlot({ plot(price/1000 ~ month, data = month_aggregate,
title = "Avg Price Vs Month", xlab = "Month", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$view_scatterplot = renderPlot({ plot(price/1000 ~ view , data = kings_house_data(),
title = "Price Vs View", xlab = "View", ylab = "Price in thousands", col = "red")})
output$condition_scatterplot = renderPlot({ plot(price/1000 ~ condition, data = kings_house_data(),
title = "Price Vs Condition", xlab = "Condition", ylab = "Price in thousands", col = "red")})
output$floors_scatterplot = renderPlot({ plot(price/1000 ~ floors, data = kings_house_data(),
title = "Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Price in thousands", col = "red")})
output$month_scatterplot = renderPlot({ plot(price/1000 ~ month, data = kings_house_data(),
title = "Price Vs Month", xlab = "Month", ylab = "Price in thousands", col = "red")})
})
}
嗨,这个错误 (invalid 'envir' argument of type 'closure'
) 意味着在 R 中,当您真正想要函数的值时,您已经将函数作为参数给出。在 Shiny 中,几乎总是有人忘记在反应性语句后添加方括号 ()
。在这种情况下,您已经为 kings_house_data
正确地完成了它,但是您忘记了 view_aggregate
、condition_aggregate
、floors_aggregate
和 month_aggregate
之后的括号
这是您的代码的更正部分
output$viewplot = renderPlot({ plot(price/1000 ~ view , data = view_aggregate(),
title = "Avg Price Vs View", xlab = "View", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$conditionplot = renderPlot({ plot(price/1000 ~ condition, data = condition_aggregate(),
title = "Avg Price Vs Condition", xlab = "Condition", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$floorsplot = renderPlot({ plot(price/1000 ~ floors, data = floors_aggregate(),
title = "Avg Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$monthplot = renderPlot({ plot(price/1000 ~ month, data = month_aggregate(),
title = "Avg Price Vs Month", xlab = "Month", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$view_scatterplot = renderPlot({ plot(price/1000 ~ view , data = kings_house_data(),
title = "Price Vs View", xlab = "View", ylab = "Price in thousands", col = "red")})
output$condition_scatterplot = renderPlot({ plot(price/1000 ~ condition, data = kings_house_data(),
title = "Price Vs Condition", xlab = "Condition", ylab = "Price in thousands", col = "red")})
output$floors_scatterplot = renderPlot({ plot(price/1000 ~ floors, data = kings_house_data(),
title = "Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Price in thousands", col = "red")})
output$month_scatterplot = renderPlot({ plot(price/1000 ~ month, data = kings_house_data(),
title = "Price Vs Month", xlab = "Month", ylab = "Price in thousands", col = "red")})
我正在 "invalid 'envir' argument of type 'closure'" 代替 R 闪亮仪表板中的图。无法找出错误。我正在尝试根据邮政编码的选择对数据进行子集化。如果有人能在这里提供帮助就太好了
library(shiny)
library(shinydashboard)
library(dplyr)
varsfilter = unique(final_kings_house_data$zipcode)
vars = unique(final_kings_house_data$zipcode)
if (interactive()) {
header <- dashboardHeader(title = "Kings County Housing Data")
sidebar <- dashboardSidebar(
sidebarSearchForm(label = "Enter a number", "searchText", "searchButton"),
sidebarMenu(
id = "tabs",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets", badgeLabel = "new",
badgeColor = "green"),
menuItem("Charts", icon = icon("bar-chart-o"),
menuSubItem("Trend Chart", tabName = "subitem1"),
menuSubItem("Scatter Plot", tabName = "subitem2")),
selectInput("filtervar", "Select zipcode", choices = vars),
checkboxGroupInput("filteroptions", "Select zipcode", choices = varsfilter)))
body <- dashboardBody(
tabItems(
tabItem("subitem1", fluidRow(
tabsetPanel(id = "tabselected",
tabPanel("Visualization", uiOutput("Tab1")),
tabPanel("Summary", uiOutput("Tab2"))))),
tabItem("widgets",
"Widgets tab content"),
tabItem("dashboard",
"Welcome!"),
tabItem("subitem2", fluidRow(
tabsetPanel(id = "tabselected",
tabPanel("Visualization", uiOutput("Tab3")),
tabPanel("Summary", uiOutput("Tab4"))
))
)))
shinyApp(
ui = dashboardPage(header, sidebar, body),
server = function(input, output,session) {
kings_house_data = reactive({
a = subset(final_kings_house_data, final_kings_house_data$zipcode == input$vars)
return(a)
})
view_aggregate = reactive({kings_house_data() %>% group_by(view) %>% summarise(price = mean(price))})
condition_aggregate = reactive({kings_house_data() %>% group_by(condition) %>% summarise(price = mean(price))})
floors_aggregate = reactive({kings_house_data() %>% group_by(floors) %>% summarise(price = mean(price))})
month_aggregate = reactive({kings_house_data() %>% group_by(month) %>% summarise(price = mean(price))})
output$Tab1 = renderUI({
mainPanel(fluidRow(
column(6,plotOutput(outputId = "viewplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "conditionplot", width="300px",height="300px"))),
fluidRow(
column(6,plotOutput(outputId = "floorsplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "monthplot", width="300px",height="300px"))))
})
output$Tab3 = renderUI({
mainPanel(fluidRow(
column(6,plotOutput(outputId = "view_scatterplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "condition_scatterplot", width="300px",height="300px"))),
fluidRow(
column(6,plotOutput(outputId = "floors_scatterplot", width="300px",height="300px")),
column(6,plotOutput(outputId = "month_scatterplot", width="300px",height="300px"))))
})
output$viewplot = renderPlot({ plot(price/1000 ~ view , data = view_aggregate,
title = "Avg Price Vs View", xlab = "View", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$conditionplot = renderPlot({ plot(price/1000 ~ condition, data = condition_aggregate,
title = "Avg Price Vs Condition", xlab = "Condition", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$floorsplot = renderPlot({ plot(price/1000 ~ floors, data = floors_aggregate,
title = "Avg Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$monthplot = renderPlot({ plot(price/1000 ~ month, data = month_aggregate,
title = "Avg Price Vs Month", xlab = "Month", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$view_scatterplot = renderPlot({ plot(price/1000 ~ view , data = kings_house_data(),
title = "Price Vs View", xlab = "View", ylab = "Price in thousands", col = "red")})
output$condition_scatterplot = renderPlot({ plot(price/1000 ~ condition, data = kings_house_data(),
title = "Price Vs Condition", xlab = "Condition", ylab = "Price in thousands", col = "red")})
output$floors_scatterplot = renderPlot({ plot(price/1000 ~ floors, data = kings_house_data(),
title = "Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Price in thousands", col = "red")})
output$month_scatterplot = renderPlot({ plot(price/1000 ~ month, data = kings_house_data(),
title = "Price Vs Month", xlab = "Month", ylab = "Price in thousands", col = "red")})
})
}
嗨,这个错误 (invalid 'envir' argument of type 'closure'
) 意味着在 R 中,当您真正想要函数的值时,您已经将函数作为参数给出。在 Shiny 中,几乎总是有人忘记在反应性语句后添加方括号 ()
。在这种情况下,您已经为 kings_house_data
正确地完成了它,但是您忘记了 view_aggregate
、condition_aggregate
、floors_aggregate
和 month_aggregate
这是您的代码的更正部分
output$viewplot = renderPlot({ plot(price/1000 ~ view , data = view_aggregate(),
title = "Avg Price Vs View", xlab = "View", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$conditionplot = renderPlot({ plot(price/1000 ~ condition, data = condition_aggregate(),
title = "Avg Price Vs Condition", xlab = "Condition", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$floorsplot = renderPlot({ plot(price/1000 ~ floors, data = floors_aggregate(),
title = "Avg Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$monthplot = renderPlot({ plot(price/1000 ~ month, data = month_aggregate(),
title = "Avg Price Vs Month", xlab = "Month", ylab = "Avg Price in thousands", type = "o", col = "red")})
output$view_scatterplot = renderPlot({ plot(price/1000 ~ view , data = kings_house_data(),
title = "Price Vs View", xlab = "View", ylab = "Price in thousands", col = "red")})
output$condition_scatterplot = renderPlot({ plot(price/1000 ~ condition, data = kings_house_data(),
title = "Price Vs Condition", xlab = "Condition", ylab = "Price in thousands", col = "red")})
output$floors_scatterplot = renderPlot({ plot(price/1000 ~ floors, data = kings_house_data(),
title = "Price Vs No. of Floors", xlab = "No. of Floors", ylab = "Price in thousands", col = "red")})
output$month_scatterplot = renderPlot({ plot(price/1000 ~ month, data = kings_house_data(),
title = "Price Vs Month", xlab = "Month", ylab = "Price in thousands", col = "red")})