这是对R Studio中mtcars数据集的线性回归。我正在尝试创建应用程序。没运气。工作了好几天。对我不熟悉编程没有帮助。谢谢您的帮助。
这是对的吗?
#server.r
data(mtcars)
mtdata<-mtcars
fit<-lm(mpg~cyl+hp+wt+qsec+am+gear,data=mtcars)
shinyServer(function(input, output) {
formulaText <- reactive({
#Not sure what this does.
paste("mpg ~", input$variable)
})
output$caption <- renderText({ # Not sure what this does.
formulaText()
})
# I am lost here. I think this part needs to 'mate up' with ui.r
output$mpgPlot <- renderPlot({
boxplot(as.formula(formulaText()), # I don't understand.
data = mtdata,
outline = input$outliers) # I don't understand.
})
})# I don't understand.
# ui.R
#fit<-lm(mpg~cyl+hp+wt+qsec+am+gear,data=mtcars)
shinyUI(fluidPage(
titlePanel("Guess which variables affect MPG!"),
# I understand sliders, radio buttons. There is a disconnect between ur
# and server.
fluidRow(
# I understand this.
column(3,
radioButtons("radio", label = h3("Cylinders"), # I understand.
choices = list("4 Cyl" = 4, "6 Cyl" =6, # I understand.
"8 Cyl" = 8),selected = 1)),
radioButtons("radio", label = h3("Number of Gears"),
choices = list("3" = 3, "4" =4,
"5" = 5),selected = 1),
#I understand this.
column(3,
selectInput("select", label = h3("Transmission Type"),
choices = list("Manual " = 1, "Automatic" =
2), selected = 1)),
fluidRow(
column(3,
sliderInput("slider1", label = h3("Horse Power"),
min = 52, max = 230, step = 5,value = 52),
sliderInput("slider2", label = h3("Weight, in tons"),
min = 1.513, max = 5.42,step = .1, value =
"min" ),
sliderInput("slider3", label = h3("Quarter Mile, in
Seconds"),
min = 14.60, max = 22.90, step = .1, value
# I don't understand.
="min" )), # I don't understand.
mainPanel( # I don't understand.
h3(textOutput("caption")), # I don't understand this.
plotOutput("mpgPlot") # I don't understand this.
) # I don't understand.
) # I don't understand.
) # I don't understand.
))
答案 0 :(得分:1)
未定义server.R期望来自ui.R的一些输入(input$variable
和input$outliers
)。如果您将以下控制器添加到您的ui.R,您将拥有一个有效的应用程序
radioButtons("variable", label=h3("Variable"),
choices = list("Cylinders"="cyl",
"Gears"="gear",
"Transmission"="am",
"Horse Power"="hp",
"Weight, in tons"="wt",
"Quarter Mile, in seconds"="qsec"),
selected="cyl"),
checkboxInput("outliers", "Show outliers", FALSE))