Skip to content

Instantly share code, notes, and snippets.

@datalorax
Last active August 5, 2021 16:22
Show Gist options
  • Save datalorax/c32e6eb165bf54d351d9f0d893f7efb0 to your computer and use it in GitHub Desktop.
Save datalorax/c32e6eb165bf54d351d9f0d893f7efb0 to your computer and use it in GitHub Desktop.
library(shiny)
library(shinyWidgets)
library(ggplot2)
library(equatiomatic)
library(gtsummary)
library(gt)
ui <- fluidPage(
titlePanel("equatiomatic w/Shiny"),
sidebarLayout(
sidebarPanel(
multiInput(
inputId = "xvars", label = "Select predictor variables :",
choices = names(mpg)[-8],
selected = "displ"
)
),
mainPanel(
uiOutput("eq"),
gt_output("tbl")
)
)
)
server <- function(input, output) {
model <- reactive({
form <- paste("hwy ~ ", paste(input$xvars, collapse = " + "))
lm(as.formula(form), mpg)
})
output$eq <- renderUI(
withMathJax(
helpText(
equatiomatic:::format.equation(
extract_eq(model(), wrap = TRUE, terms_per_line = 3)
)
)
)
)
output$tbl <- render_gt({
as_gt(tbl_regression(model()))
})
}
shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment