简体   繁体   中英

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. 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:

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'

I can't seem to find anything specific to this anywhere :-/

THANKS!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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