This is a simple R Shiny app which uses the data(mrcars), to make a plot and present data. Here is the Code: library(shiny) library(datasets)
Nguyen Tan Dat
Data Analysis
This is a simple R Shiny app which uses the data(mrcars), to make a plot and present data. Here is the Code: library(shiny) library(datasets)
shinyUI( navbarPage("Just a Shiny Application", tabPanel("Analysis", fluidPage( titlePanel("The relationship between variables and miles per gallon (MPG)"), sidebarLayout( sidebarPanel( selectInput("variable", "Variable:", c("Number of cylinders" = "cyl", "Displacement (cu.in.)" = "disp", "Gross horsepower" = "hp", "Rear axle ratio" = "drat", "Weight (lb/1000)" = "wt", "1/4 mile time" = "qsec", "V/S" = "vs", "Transmission" = "am", "Number of forward gears" = "gear", "Number of carburetors" = "carb" )),
checkboxInput("outliers", "Show BoxPlot's outliers", FALSE) ),
mainPanel( h3(textOutput("caption")),
tabsetPanel(type = "tabs", tabPanel("BoxPlot", plotOutput("mpgBoxPlot")), tabPanel("Regression model", plotOutput("mpgPlot"), verbatimTextOutput("fit") ) ) ) ) ) ),
tabPanel("Check the Source Code", h2("All the Source code can be find in courera"), hr(), h3("Here : Peer Assessments /Regression Models Course Project"), helpText("You work for Motor Trend, a magazine about the automobile industry Looking at a data set of a collection of cars, they are interested in exploring the relationship", "between a set of variables and miles per gallon (MPG) (outcome). They are particularly interested in the following two questions: Is an automatic or manual transmission better for MPG. Quantify the MPG difference between automatic and manual transmissions"),
h3("Important"), p("A data frame with 32 observations on 11 variables."),
a("https://www.coursera.org/learn/regression-models") ), tabPanel("More Data Detail", h2("Motor Trend Car Road Tests"), hr(), h3("Description"), helpText("The data was extracted from the 1974 Motor Trend US magazine,", " and comprises fuel consumption and 10 aspects of automobile design and performance", " for 32 automobiles (1973–74 models)."), h3("Format"), p("A data frame with 32 observations on 11 variables."),
p(" [, 1] mpg Miles/(US) gallon"), p(" [, 2] cyl Number of cylinders"), p(" [, 3] disp Displacement (cu.in.)"), p(" [, 4] hp Gross horsepower"), p(" [, 5] drat Rear axle ratio"), p(" [, 6] wt Weight (lb/1000)"), p(" [, 7] qsec 1/4 mile time"), p(" [, 8] vs V/S"), p(" [, 9] am Transmission (0 = automatic, 1 = manual)"), p(" [,10] gear Number of forward gears"), p(" [,11] carb Number of carburetors"),
h3("Source"),
p("Henderson and Velleman (1981), Building multiple regression models interactively. Biometrics, 37, 391–411.") ), tabPanel("Go back to my Github repository", a("https://github.com/mrdat0194/Shiny"), hr(), h2("I hope you like the Shiny App"), h2("The name of the repositorie is DataProducts") ) ) )
shinyServer(function(input, output) {
formulaText <- reactive({
paste("mpg ~", input$variable)
})
formulaTextPoint <- reactive({
paste("mpg ~", "as.integer(", input$variable, ")")
})
fit <- reactive({
lm(as.formula(formulaTextPoint()), data=mpgData)
})
output$caption <- renderText ({ formulaText()
})
output$mpgBoxPlot <- renderPlot ({
boxplot(as.formula( ormulaText()), data = mpgData, outline = input$outliers)
})
output$fit <- renderPrint({ summary(fit()) })
output$mpgPlot <- renderPlot({ with(mpgData, { plot(as.formula(formulaTextPoint())) abline(fit(), col=2) }) })
})