library(ggplot2)
library(shiny)
Question 1:
shinyApp(
ui = fluidPage(
sliderInput("span5", label = "Span adjustment:",
min = 1, max = 6.9, value = 1, step = 0.2),
plotOutput("irisplot"), # add plot
textOutput("span_val"), # add text
dataTableOutput("data_table"), ## add data table
verbatimTextOutput("summary_var") # add print output
),
server = function(input, output){
output$irisplot <- renderPlot({
ggplot(iris, aes(x=Petal.Length, y=Petal.Width)) + geom_point(aes(color=Species)) +
geom_smooth(method="loess", formula=y~x, se=FALSE, span=input$span5) + theme_bw()
})
output$span_val <- renderText({
paste0("Span = ", input$span5)
})
output$summary_var <- renderPrint({
summary(iris[, c("Petal.Length", "Petal.Width")])
})
}
)
Question 2:
shinyApp(
ui = fluidPage(
sliderInput("span5", label = "Span adjustment:",
min = 0.2, max = 0.9, value = 0.3, step = 0.1),
plotOutput("mtcarsplot"), # add plot
textOutput("span_val"), # add text
dataTableOutput("data_table"), ## add data table
verbatimTextOutput("summary_var") # add print output
),
server = function(input, output){
output$mtcarsplot <- renderPlot({
ggplot(mtcars, aes(x=disp, y=mpg)) + geom_point() +
geom_smooth(method="loess", formula=y~x, se=FALSE, span=input$span5) + theme_bw()
})
output$span_val <- renderText({
paste0("Span = ", input$span5)
})
output$summary_var <- renderPrint({
summary(mtcars[, c("disp", "mpg")])
})
}
)