Created
March 15, 2021 11:19
-
-
Save faragocsaba/c81c8f345915913022c15e656d74cab3 to your computer and use it in GitHub Desktop.
Interactive model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
shinyServer(function(input, output) { | |
model <- reactive({ | |
brushed_data <- brushedPoints(trees, input$brush1, xvar = "Girth", yvar = "Volume") | |
if (nrow(brushed_data) < 2) { | |
return(NULL) | |
} | |
lm(Volume ~ Girth, data = brushed_data) | |
}) | |
output$slopeOut <- renderText({ | |
if (is.null(model())) { | |
"No Model Found" | |
} else { | |
model()[[1]][2] | |
} | |
}) | |
output$intOut <- renderText({ | |
if (is.null(model())) { | |
"No Model Found" | |
} else { | |
model()[[1]][1] | |
} | |
}) | |
output$plot1 <- renderPlot({ | |
plot(trees$Girth, trees$Volume, xlab = "Girth", | |
ylab = "Volume", main = "Tree Measurements", | |
cex = 1.5, pch = 16, bty = "n") | |
if (!is.null(model())) { | |
abline(model(), col = "blue", lwd = 2) | |
} | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
shinyUI(fluidPage( | |
titlePanel("Visualize Many Models"), | |
sidebarLayout( | |
sidebarPanel( | |
h3("Slope"), | |
textOutput("slopeOut"), | |
h3("Intercept"), | |
textOutput("intOut") | |
), | |
mainPanel( | |
plotOutput("plot1", brush = brushOpts( | |
id = "brush1" | |
)) | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment