简体   繁体   English

在Shiny中引用具有反应性输入变量的列

[英]referencing a column with reactive input variable in Shiny

Trying to use an input variable value to reference the indicated column within the "results" data frame using the lm function in Shiny. 通过Shiny中的lm函数尝试使用输入变量值引用“结果”数据框中的指示列。 i've tested this in the console and it works fine but not when i actually run the app. 我已经在控制台中对此进行了测试,但工作正常,但当我实际运行该应用程序时却无法正常工作。

I don't think all of the code is necessary (but i will be happy to include more if need be) so here is the important bits from server.r: 我不认为所有代码都是必需的(但是如果需要,我会乐意包含更多代码),所以这是server.r的重要内容:

compareVar2 <- reactive({
    if(input$compareVar2 == 'first'){
        return (results$firstPostScore)
    }else if(input$compareVar2 == 'last'){
        return (results$lastPostScore)
    }else if(input$compareVar2 == 'avg'){
        return (results$avgPostScore)
    }else {return (results$avgPostScore)} #just as a fall-back default

output$analysis <- renderPrint({
    analysis <- lm(preScore ~ compareVar2, data = results)
    return (summary(analysis))
})

I get the following error message: 我收到以下错误消息:
Error in model.frame.default(formula = preScore ~ compareVar2, data = results, : invalid type (closure) for variable 'compareVar2' model.frame.default中的错误(公式= preScore〜compareVar2,数据=结果,:变量'​​compareVar2'的类型无效(关闭)

I can't seem to find anything specific to this anywhere :-/ 我似乎在任何地方都找不到特定于此的任何东西:-/

THANKS! 谢谢!

compareVar2是一个函数,因此应将其称为compareVar2():

analysis <- lm(preScore ~ compareVar2(), data = results)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM