R Shiny ggplot2 Support Vector Machine Trend Line -


i have been frustrated ages; cannot trend line appear:

library(shiny) ui = pagewithsidebar(   headerpanel("twitter engagement correlations"),     sidebarpanel(       selectinput("c", label = "variable:",                      choices = colnames(dataset))       ),   mainpanel(     plotoutput('plot1')   ) ) server = function(input, output) {    reactive({     library(e1071)     regressor = svm(engagements ~ character.count,                      data = dataset,                     type = 'eps-regression')   })    output$plot1 = renderplot({     print(ggplot() +       geom_point(aes(x = dataset[,input$c], y = dataset$engagements),                  colour = 'red') +         geom_line(aes(x = dataset$character.count, y = predict(regressor, newdata = dataset)),                   colour = 'blue') +       ggtitle('svr regression model') +       xlab(input$c) +       ylab('engagements'))     }) }     shinyapp(ui = ui, server = server) 

the error code 'object 'regressor' not found' appears , don't know how solve this? in advance

your regressor variable not defined inside scope of plot1. need name reactive:

getregressor <- reactive({    library(e1071)    svm(engagements ~ character.count,                 data = dataset,                type = 'eps-regression')  }) 

now can call define variable regressor inside plot1:

output$plot1 <- renderplot({   regressor <- getregressor()   ... }) 

Comments