我多年来一直对此感到沮丧;我无法看到趋势线:
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)
错误代码' object' regressor'找不到'出现了,我不知道如何解决这个问题? 提前感谢您的帮助
答案 0 :(得分:0)
您的regressor
变量未在plot1
范围内定义。您需要为reactive
:
getRegressor <- reactive({
library(e1071)
svm(Engagements ~ Character.count,
data = dataset,
type = 'eps-regression')
})
现在您可以调用它来定义 regressor
内的变量plot1
:
output$plot1 <- renderPlot({
regressor <- getRegressor()
...
})