我正在尝试创建一个应用程序,创建一个线性回归模型,根据用户输入确定解释变量。
install.packages("shiny")
install.packages('rsconnect')
library(rsconnect)
deployApp()
library(shiny)
data <- read.csv("Teams.csv")
shinyUI(
fluidPage(
titlePanel("What does it take for a Hockey Team to Win?"),
sidebarLayout(
sidebarPanel(
selectInput("Explan1","Explanatory Variable 1",choices = colnames(data)),
selectInput("Explan2","Explanatory Variable 3",choices = colnames(data)),
selectInput("Explan3","Explanatory Variable 3",choices = colnames(data))
),
mainPanel(
actionButton("analysis","Analyze!"),
verbatimTextOutput("modelSummary")
shinyServer(
function(input,output) (
observeEvent(input$analysis, {
reactive(
data <- read.csv("Teams.csv"),
attach(data),
response = "Wins",
explan1=input$Explan1,
explan2=input$Explan2,
explan3=input$Explan3,
model <- lm(response~explan1+explan2+explan3),
output$modelSummary <- renderPrint(
summary(model)
)
)
}
)
)
)
当我在R studio中运行应用程序时,它基本上只是创建一个循环,它一直要求安装包。此外,如果我在shiny
上部署应用,则只需说明
错误:发生了错误。检查您的日志或联系该应用程序 作者澄清。
我对R很新,但我真的不明白我的代码有什么问题。我已经使用了几个资源来创建代码,老实说这对我来说似乎都很好。
我将不胜感激任何帮助。
答案 0 :(得分:0)
#install.packages("shiny") #install.packages used once, only in the first installation then use library()
#rsconnect & deployApp() use when you want to deploy your App to shinyapps.io
#install.packages('rsconnect')
#library(rsconnect)
#deployApp()
library(shiny)
data <- read.csv("Teams.csv") #Load data once at startup
ui <- shinyUI(
fluidPage(
titlePanel("What does it take for a Hockey Team to Win?"),
sidebarLayout(
sidebarPanel(
selectInput("Explan1","Explanatory Variable 1",choices = colnames(data)),
selectInput("Explan2","Explanatory Variable 3",choices = colnames(data)),
selectInput("Explan3","Explanatory Variable 3",choices = colnames(data))
),
mainPanel(
actionButton("analysis","Analyze!"),
verbatimTextOutput("modelSummary")))))
server<- shinyServer(function(input,output) {
mod <- reactiveValues()
observeEvent(input$analysis, {
mod$response <- data[,"Wins"]
mod$explan1=data[,input$Explan1]
mod$explan2=data[,input$Explan2]
mod$explan3=data[,input$Explan3]
mod$model <- lm(mod$response ~ mod$explan1+mod$explan2+mod$explan3)
}
)
output$modelSummary <- renderPrint(
if(is.null(mod$response))
{return("Please use the panel on the left to enter the required information and press “Analyze!”")} else {summary(mod$model)})
}
)
shinyApp(ui,server)
请检查https://shiny.rstudio.com/tutorial/。我希望它有所帮助。