2016-05-12 25 views
1

這是R Studio中mtcars數據集的線性迴歸。我正在嘗試創建應用程序。沒有運氣。工作幾天。對我來說編程不熟悉並沒有幫助。謝謝您的幫助。閃亮的ui.r和server.r - 我找不到讓應用程序工作的代碼

這是正確的嗎?

#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

您是否也可以分享您的ui.R代碼? –

+0

嗨拉斐爾。上面都是ui.r和server.r。如果你幫我,我會付給你的。我是認真的。 – xanstorm

+1

你有沒有經過[閃亮 - 入門](http://shiny.rstudio.com/tutorial/)課程? – SymbolixAU

回答

1

一些server.R從ui.R期待輸入的未定義(input$variableinput$outliers)。如果您將以下控制器添加到您的ui.R中,您將可以使用Shiny應用程序

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)) 
+0

如果您可以諮詢,請告訴我。我想在有問題時可以聯繫我。我將每小時或每次事件付給你。這可以嗎? – xanstorm

+0

我會建議檢查http://shiny.rstudio.com/,他們有一些非常好的教程在那裏。我認爲這將是一種更快捷的學習方式。同時,我對你的應用程序採取了一些自由,並創建了一個github存儲庫(https://github.com/DGKarlsson/mtcars_shiny),我也試着添加一些解釋性評論。如果您還有其他問題,可以隨時在這裏發佈。 – DGKarlsson

+0

我會檢查出來,並感謝您的幫助!你超越了呼聲。謝謝。你可以諮詢嗎?我需要幫助。 – xanstorm

相關問題