简体   繁体   English

R Shiny中类型为“ closure”的无效“ envir”参数

[英]invalid 'envir' argument of type 'closure' in R shiny

I am getting "invalid 'envir' argument of type 'closure'" in the place of the plots in R shiny dashboard. 我在R Shiny仪表板中的绘图位置出现“类型为'closure'的无效'envir'参数'”。 Not able to figure out the error. 无法找出错误。 I am trying to subset the data depending on the selection of the zipcode. 我试图根据邮政编码的选择对数据进行子集化。 It would be great if anyone could help here 如果有人可以在这里帮助,那就太好了

 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")})

  })
}

Hi this error ( invalid 'envir' argument of type 'closure' ) means in R that you have given a function as an argument, when you really wanted the value of the function. 嗨,这个错误( invalid 'envir' argument of type 'closure' )意味着在R中,当您确实需要该函数的值时,已将其作为参数提供。 In Shiny is this almost always that one have forgotten to add the brackets () after a reactive statment. 在Shiny中,几乎总是有人忘记了在反应性陈述后加上方括号() In this case you have done it correctly for kings_house_data but you forgotten the brackets after view_aggregate , condition_aggregate , floors_aggregate and month_aggregate 在这种情况下,您已经为kings_house_data正确完成了操作,但是您忘记了view_aggregatecondition_aggregatefloors_aggregatemonth_aggregate之后的括号

Here is the corrected part of your code 这是代码的更正部分

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")})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 eval(predvars,data,env)中的错误:类型为“ closure”的无效“ envir”参数 - Error in eval(predvars, data, env): invalid 'envir' argument of type 'closure' R中带有线性模型的purrr:类型为&#39;character&#39;的无效&#39;envir&#39;参数 - purrr with linear model in R: invalid 'envir' argument of type 'character' Coxph,类型为“字符”的无效“ envir”参数 - Coxph, invalid 'envir' argument of type 'character' ls中的错误(envir = envir,all.names = private):R中的&#39;envir&#39;参数无效 - Error in ls(envir = envir, all.names = private) : invalid 'envir' argument in R 在“ apply”中使用“ with”时,“ character”类型的“ environment”参数无效 - “invalid 'envir' argument of type 'character” when using “with” inside of “apply” eval(predvars,data,env)中的错误:类型为&#39;character&#39;的&#39;envir&#39;参数无效 - Error in eval(predvars, data, env) : invalid 'envir' argument of type 'character' shiny 中带有 verbatimTextOutput 的参数类型无效 - Invalid argument type with verbatimTextOutput in shiny 尝试使用R中的闪亮应用程序创建一个未来值计算器并得到错误:“ cat”无法处理参数1(类型“ closure”) - Trying to create a future value calculator with shiny app in R and get error: argument 1 (type 'closure') cannot be handled by 'cat' &#39;闭合&#39;类型的对象不是子集:R闪亮的应用程序 - object of type 'closure' is not subsettable: R shiny App 类型“ closure”的对象在R Shiny中不可子集化 - object of type ‘closure’ is not subsettable in R Shiny
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM