首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >unclass(x)中的r闪亮错误:不能使用dplyr筛选函数取消环境的类

unclass(x)中的r闪亮错误:不能使用dplyr筛选函数取消环境的类
EN

Stack Overflow用户
提问于 2018-07-30 21:29:40
回答 1查看 2.7K关注 0票数 3

我试图在一个反应函数中过滤一个数据集,这样我就可以上下移动一个滑块,并改变数据集的大小。

我使用名为"sliderfordata“的滑块作为对名为”年度数据“的反应性函数的输入,因此我使用该反应性函数作为输出$图表的数据输入。--我正在使用的数据集--也是mtcar

错误消息::unclass(x):无法取消环境类中的错误

当我选择要上传为数据的文件时,这个过程将映射到从文件路径读取数据文件的reactivefunc。

任何帮助都很感谢

服务器代码

代码语言:javascript
运行
复制
library("dplyr")
server <- function(input, output, session) {


  yeardata <- reactive({
    mtcarslist <- reactivefunc()
    df <- mtcarslist %>%
      filter(mpg >= input$sliderfordata)


  })
  output$chart <- reactive({

    dataframe <- yeardata()
    gggraph <-
      ggplot(dataframe, aes(x = mpg , y = hp))
    gggraph <- gggraph + geom_point()
    gggraph
  })



  reactivefunc <- reactive(
    csv <- read.csv(input$file$datapath)
  )


  # scatter plot the mtcars dataset - mpg vs hp
  output$graph <- renderPlot({
    # filename = input$file$datapath
    # csv <- read.csv(filename)

    # If more than 1 category, you can do this (put in a if state)
    # If filepath is put in
    csvread <- reactivefunc()
    x_axis <- input$xaxis
    y_axis <- input$yaxis
    rangemin <- as.numeric(input$val1)
    rangemax <- as.numeric(input$val2)

    # csv <-
    #   csvread %>%
    #   filter(
    #     x_axis <- csvread$x_axis < as.numeric(input$val2)
    #     # y_axis <- csvread$y_axis < as.numeric(input$val2)
    #   )

    size <- input$size
    color <- input$color
    gg <-
      ggplot(reactivefunc(), aes_string(x = x_axis, y = y_axis, size = size, colour = color))
    gg <- gg + geom_point()
    gg
  })

  output$hist <- renderPlot({
      x_axis <- input$xaxis
      csvread <- reactivefunc()


      ggplot(reactivefunc(), aes_string(x= x_axis)) + geom_histogram(bins = input$bins)

  })

  # To display the mtcars dataset on the left side in the app
  output$data <- renderTable({
    reactivefunc()
  })


  output$mytable = DT::renderDataTable(reactivefunc(), selection = list(target = 'row+column'))


  # brushedPoints returns the row of data under the brush
  # brush information comes from ui to server using brushId and can be accessed using input$brushId

  output$data_brush <-  renderTable({
    n = nrow(brushedPoints(reactivefunc(), brush = input$plot_brush)) # row count will be 0 when no selection made by the brush
    if(n==0)  
      return()
    else
      brushedPoints(reactivefunc(), brush = input$plot_brush) # return rows
    # argument allRows = TRUE can also be used
    ## It will add another column (selected_) to the actual dataset. True indicates that data point 
    # corresponding to that row was under the brush. False means data corresponding to that row wasn't selected by brush



  })
}

UI代码:

代码语言:javascript
运行
复制
library(shiny)
library(ggplot2)
library(shinydashboard)

## ui code starts here ## 
data <- read.csv(file.choose())
datacolnames <- colnames(data)
datarownames<- data[,1]


datacolnames <- datacolnames[-1]
length <- length(datacolnames)
length
data
# Works!@

  maxvector <- c()
  for (i in 2:length) {
    maxvector <- append(maxvector, max(data[,i]))
    i <- i + 1
  }
maxvector <- max(maxvector)
maxvector

minvector <- c()
for (i in 2:length) {
  minvector <- append(minvector, min(data[,i]))
  i <- i + 1
}
minvector <- min(minvector)
minvector













# max <- max(data[,c(:11]))
# min <- min(data[,2])
# max

ui <- 
  dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
      h4("Interactive plots - select data points in plot - return the rows of data that are selected by brush"),

      # brush argument will enable the brush, sends the data point information to the server side
      # at the server side the data points under the brush related information can be read through input$BRUSHID
      plotOutput(outputId = "graph", brush = "plot_brush"), # brush ID is plot_brush
      plotOutput("chart"),

      fluidRow(
        box(width = 5,title = "Charting", status = "warning", solidHeader = T,
            fileInput("file", "Upload the File"),
            h5("Max file size to upload is 5 MB"),
            radioButtons("sep", "Seperator", choices = c(Comma = ",", Period = ".")),
            selectInput("xaxis","Select the Model number", datacolnames),
            selectInput("yaxis", "Select the Type number", datacolnames),
            selectInput("size", "Select the Size", datacolnames),
            selectInput("color", "Select the Color", datacolnames),
            textInput("val1", "Type in the Beginning Value you Want to see", minvector),
            textInput("val2", "Type in the End Value you want to see", maxvector),
            sliderInput("bins", "Data Range", min = minvector, max = maxvector, 10),

            sliderInput("sliderfordata", "Range of X Data Values", min = 10, max = 100, value = 10)
            # sliderInput("y", "Range of Y Data Values", min = 10, max = 100, value = c(10,100))







            # Instead of sliders, we could have text inputs that map to the indexing
            # sliderInput("obs", "Data Range:",  
            #             min = minvector, max = maxvector, value = c(0,472))
        ),
        column(width=5, tags$b(tags$i("Rows corresponding to datapoints under brush")),  tableOutput("data_brush"), offset = 2)

      ),
      fluidPage(
        plotOutput("hist")
      ),


      # left side actual dataset and right side the rows for datapoints selected by brush
      # defined the width of each column and also some styling (bold & italics) using tags
      fluidPage(
        box(width = 12, tags$b(tags$i("Actual Dataset")), DT::dataTableOutput("mytable"))
      )


    )
  )

# download the data button
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-11 14:44:09

问题似乎是在图表输出中使用reactive函数而不是renderPlot函数。对于任何有这个问题并寻找可能的答案的人来说。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51602543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档