给出错误:使用反应函数后,类型为“ closure”的对象不可子集化

时间:2018-08-02 02:07:33

标签: r

我在读取文件时正在server.R中使用反应函数,但使用Boxplot后却给出错误。     服务器从ui.R bt获取输入值,它不能正常工作。 错误:“关闭”类型的对象不可子集化。

在这里,我放置了ui.R代码以及server.R

ui.R

    library(shiny)

    shinyUI(pageWithSidebar(

      # Application title
      headerPanel("Generate Graphs"),

      # Sidebar with controls to select the variable to plot against mpg
      # and to specify whether outliers should be included


      sidebarPanel(
        data <- data.frame(read.csv("Book1.csv")),

        selectInput("variable1","City:",c(data[2]),multiple = TRUE),
        selectInput("variable2", "Parameter:",
                    list("NOx","NO2/Ox","Ox","NO","NO2","O3","PM 10","PM 2.5")),

       dt <- dateInput("date","Date:",value = "2018-1-08",format = "mm/dd/yyyy"),

       timeInput("time", "Time:", value = Sys.time()),



        checkboxInput("outliers", "Show outliers", FALSE)
      ),

       mainPanel(
        h3(textOutput("caption")),

        plotOutput("mpgPlot")
      )
    ))

    **Server.R**

    library(shiny)
    library(datasets)

    shinyServer(function(input, output) {
      observeEvent(input$variable1, {
        print(paste0("You have chosen: ", input$variable1))
      })
                  data <- reactive(read.csv(input$variable1))

          f <- reactiveValues(df = data)

           observeEvent(input$variable1, {
                 print(paste0("You have chosen: ", input$variable1))
          })



         output$mpgPlot <- renderPlot({

          boxplot(as.numeric(df$NOx)~as.numeric(df$Time),ylab="Time",xlab="Parameter",Main="Data Related City")
          })


    })

0 个答案:

没有答案