I am practicing some shiny app creating using the baeskel
data in the alr4 package. My goal is to create a selectInput dropdown menu so the user can select which regression line to plot. I am uncertain how to arrange the code in the server part. So far, for one plotted line I have created this:
library(alr4)
data("baeskel")
ui <- fluidPage(
sidebarLayout(position="left",
sidebarPanel("sidebarPanel", width=4),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("baeskal Data", tableOutput("table")),
tabPanel("Polynomial Regression", plotOutput("polyplot"))
)
)
)
)
server <- function(input, output){
output$table <- renderTable({
baeskel
})
x <- baeskel$Sulfur
y <- baeskel$Tension
output$polyplot <- renderPlot({
plot(y~x, pch = 16,xlab="Sulfur",ylab="Tension",
main = "Observed Surface Tension of\nLiquid Copper with Varying Sulfur Amount")
linear_mod = lm(y~x, data = baeskel)
linear_pred = predict(linear_mod)
lines(baeskel$Sulfur, linear_pred,lwd=2,col="blue")
})
}
shinyApp(ui = ui, server = server)
It works really well. My next goal is to add another regression line as follows:
quadratic_mod <- lm(Tension ~ poly(Sulfur, 2), data = baeskel)
quadratic_pred <- predict(quadratic_mod)
lines(baeskel$Sulfur, quadratic_pred, lwd = 2, col = "green")
However I would like to use the selectInput function as follows (not pictured in the sidebarlayout yet):
selectInput(inputId = , "Choose Regression Line:", c("Linear", "Quadratic"))
I do not know how to choose the inputId so it can gather the information from each regression line.