【发布时间】:2016-05-17 10:23:51
【问题描述】:
我正在尝试从 Shiny 应用程序中的各种滑块中获取输入并将它们合并到一个表格中,但是,我不断收到以下错误:
Error in UseMethod("xtable") :
no applicable method for 'xtable' applied to an object of class "c('double', numeric')"
Error in UseMethod("xtable") :
no applicable method for 'xtable' applied to an object of class "reactive"
Error in as.vector(x, mode) :
cannot coerce type 'closure' to vector of type 'any'
我尝试了很多想法,但仍然无法实现。我也没有找到任何好的例子或解释作为指导。
我只需要一些简单的东西,用滑块的结果填充表格,然后能够通过renderTable() 打印表格。
我拥有的从滑块捕获输入的代码如下:
sliderInput(inputId = "a.w1.a", label = "Investment on advocacy", min = 0, max = 1000000, step = 50000, value = 0),
sliderInput(inputId = "a.w1.b", label = "Investment on B", min = 0, max = 1000000, step = 50000, value = 0)
由此,我能够创建一个反应性对象,然后让我能够成功绘制:
output$fund.a.w1.alloc <- reactive(input$a.w1.a + input$a.w1.b + input$a.w1.c + input$a.w1.d)
output$fund.a.w1.p <- renderPlot(barplot(d.funds.a.w1(), main = "Expenditure strategy (1000's USD)", col = "blue"))
但是,当我尝试创建具有相同内容的表格或矩阵时,我似乎没有得到正确的答案。我尝试过类似的东西:
fund.w1 <- matrix(c(reactive(input$a.w1.a/1000, input$a.w1.b/1000, input$a.w1.c/1000, input$a.w1.d/1000)), nrow = 2, ncol = 2)
或者这个:
fund.w1 <- reactive(matrix(c(input$a.w1.a/1000, input$a.w1.b/1000, input$a.w1.c/1000, input$a.w1.d/1000), nrow = 2, ncol = 2))
或者这个:
fund.w1 <- matrix(reactive(c(input$a.w1.a/1000, input$a.w1.b/1000, input$a.w1.c/1000, input$a.w1.d/1000)), nrow = 2, ncol = 2)
我什至试着看看数据对象是否可以自己组成一个表,但它不起作用。
事实上,它甚至没有像这样简单的事情:
output$fund.w1.f <- renderTable({input$a.w1.a/1000})
或者作为(之前创建过矩阵):
fund.w1.f.test[1,1] <- renderText(input$a.w1.a)
非常感谢您的帮助。
【问题讨论】:
-
你必须在你的帖子中包含你的代码,否则真的很难提供帮助!
-
这就是问题所在。我没有太多关于那部分的代码,因为我找不到任何有用的东西。我会将我以前的一些尝试添加到原始问题中,并查看它可以帮助您帮助我。非常感谢您的处置!我真的很感激。
-
嗨,@MLavoie,刚刚进行了更改以试图澄清问题。谢谢!
标签: r user-input shiny-server shiny