library(shiny)
library(tidyAML)
library(recipes)
library(DT)
library(glmnet)
library(tidymodels)
library(reactable)
tidymodels_prefer()
<- fluidPage(
ui titlePanel("TidyAML Model Builder"),
sidebarLayout(
sidebarPanel(
fileInput("file", "Upload your data file (csv or txt):"),
selectInput("dataset",
"Choose a built-in dataset:",
choices = c("mtcars", "iris")
),selectInput("predictor_col",
"Select the predictor column:",
choices = NULL
),selectInput("model_type",
"Select a model type:",
choices = c("regression", "classification")),
selectInput("model_fn", "Select a model function:",
choices = c("all","lm","brulee","gee","glm",
"glmer","glmnet","gls","lme",
"lmer","stan","stan_glmer",
"Cubist","hurdle","zeroinfl","earth",
"rpart","dbarts","xgboost","lightgbm",
"partykit","mgcv","nnet","kknn","ranger",
"randomForest","xrf","LiblineaR","kernlab"
)
),actionButton("build_model", "Build Model"),
verbatimTextOutput("recipe_output")
),mainPanel(
verbatimTextOutput("model_table"),
reactableOutput("model_reactable")
)
)
)
<- function(input, output, session) {
server
<- reactive({
data if (!is.null(input$file)) {
<- read.csv(
df $file$datapath,
inputheader = TRUE,
stringsAsFactors = FALSE
)updateSelectInput(
session, "predictor_col",
choices = names(df)
)return(df)
else if (!is.null(input$dataset)) {
} <- get(input$dataset)
df updateSelectInput(
session, "predictor_col",
choices = names(df)
)return(df)
}
})
<- eventReactive(input$predictor_col, {
recipe_obj <- recipe(as.formula(paste(input$predictor_col, "~ .")),
rec data = data()
|>
) step_normalize(all_numeric(), -all_outcomes())
return(rec)
})
<- reactive({
model_fn switch(input$model_fn,
"all" = "all",
"lm" = "lm",
"brulee" = "brulee",
"gee" = "gee",
"glm" = "glm",
"glmer" = "glmer",
"glmnet" = "glmnet",
"gls" = "gls",
"lme" = "lme",
"lmer" = "lmer",
"stan" = "stan",
"stan_glmer" = "stan_glmer",
"Cubist" = "Cubist",
"hurdle" = "hurdle",
"zeroinfl" = "zeroinfl",
"earth" = "earth",
"rpart" = "rpart",
"dbarts" = "dbarts",
"xgboost" = "xgboost" ,
"lightgbm" = "lightgbm",
"partykit" = "partykit",
"mgcv" = "mgcv",
"nnet" = "nnet",
"kknn" = "kknn",
"ranger" = "ranger",
"randomForest" = "randomForest",
"xrf" = "xrf",
"LiblineaR" = "LiblineaR",
"kernlab = kernlab")
})
<- eventReactive(input$build_model, {
model if (input$model_type == "regression") {
<- fast_regression(.data = data(),
mod .rec_obj = recipe_obj(),
.parsnip_eng = model_fn())
else if (input$model_type == "classification") {
} <- fast_classification(.data = data(),
mod .rec_obj = recipe_obj(),
.parsnip_eng = model_fn())
}return(mod)
})
$recipe_output <- renderPrint({
outputif (!is.null(input$predictor_col)) {
summary(recipe_obj())
}
})
$model_table <- renderPrint({
outputif (input$build_model > 0) {
print(model())
}
})
$model_reactable <- renderReactable({
outputif (input$build_model > 0) {
reactable(model())
}
})
}
shinyApp(ui = ui, server = server)
Introduction
Yesterday I spoke about building tidymodels
models using my package {tidyAML}
and {shiny}
. I have made an update to it, and will continue to make updates to it this week.
I have added all of the supported engines for regression problems only, NOT classification yet, that will be tomorrow’s work. I will then add a drop down for users to pick which backend function they want to use from {parsnp}
like linear_reg()
.
Here are some pictures of the udpates.
Here is the full application, please steal this code and modify for yourself, you never know what you might come up with!