【问题标题】:Use of reactive dataframe in a function在函数中使用响应式数据框
【发布时间】:2015-09-16 09:26:25
【问题描述】:

我正在尝试构建一个闪亮的应用程序。 我有三个滑块,我使用以下反应式获得数据框中滑块的最小最大值:

sliderValues <- reactive({

  data.frame(
    Name = c(as.character(attributes[1]),as.character(attributes[2]),as.character(attributes[3])),

    MaxValue = c(input$weight_1[2],
                   input$weight_2[2],
                   input$weight_3[2]),

    MinValue = c(input$weight_1[1],
                   input$weight_2[1],
                   input$weight_3[1]),

    stringsAsFactors=FALSE

  )})

现在我创建了一个函数,该函数将这个数据帧作为输入并做一些工作。 我的功能是 get_uniques 如下:

Combs <- reactive({

   get_uniques(prof_test,sliderValues)
  })

  output$values <- renderTable ({
    Combs()
              })

})

问题是我收到错误“没有适用于 'xtable' 的方法应用于类“字符”的对象”,似乎反应数据框创建了一个 xtable,当我尝试访问我得到的值时这个错误你能帮我吗? 谢谢!

【问题讨论】:

  • 使用sliderValues() 而不是sliderValues。除此之外,您需要提供一个可重现的示例。
  • 我已经尝试过了,但它不起作用我收到以下错误:“没有适用于 'xtable' 的方法应用于类“reactive”的对象“
  • renderTable 在内部使用 xtable 来生成 html 表。 Combs() 在这种情况下是返回一个字符,而不是一个类似表的结构,例如数据框或矩阵。如果您的数据框只有一列,您可能需要添加 , drop = FALSE 以防止它被强制删除。
  • 请问我应该在哪里使用 drop=FALSE ?另外我想提一下,函数 get_uniques 返回一个包含多个变量的数据帧。
  • 请提供一个可重现的例子。见stackoverflow.com/questions/5963269/…

标签: r shiny xtable


【解决方案1】:

尽量把Combs的返回值做成data.frame,即

Combs <- reactive({
   data.frame(get_uniques(prof_test,sliderValues))
  })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-20
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    相关资源
    最近更新 更多