For some reason it now requires prep(), just add it at the end of the pipe, I also improved the selection as @dodo1672 had said.
library(shinythemes)
library(shinyWidgets)
library(shiny)
library(shinydashboard)
library(recipes)
#data(mtcars)
AttributeChoices=c("mpg","cyl","disp","hp","drat","wt","qsec","vs")
# Define UI for application
ui = fluidPage(
navbarPage("R Shiny Dashboard",
tabPanel("Welcome",
tabName = "welcome",
icon=icon("door-open"),
fluidPage(theme=shinytheme("cerulean"),
h1("Welcome to my Shiny Dashboard!"),
br(),
p(strong(tags$u("What is this dashboard all about?"))),
p("I'm going to do stuff."),
br(),
p(strong(tags$u("Here's another question."))),
p("Here's my answer."),
br(),
p(strong(tags$u("How can I use this dashboard?"))),
p("You can click on any of the tabs above to see a different analysis of the data.")
)),
tabPanel("Regression",
tabname="regression",
icon=icon("calculator"),
selectInput(inputId="dependent", label = "Dependent Variables",
choices = as.list(AttributeChoices)),
uiOutput("indep"),
verbatimTextOutput(outputId = "RegOut")
)
))
# Define server logic
server <- function(input, output) {
#-------------------REGRESSION-------------------#
output$indep <- renderUI({
selectInput(inputId = "indep", label = "Independent Variables",
multiple = TRUE, choices = as.list(AttributeChoices[AttributeChoices!= input$dependent]), selected = AttributeChoices[1])
})
recipe_formula <- reactive({
req(input$indep)
mtcars %>%
recipe() %>%
update_role(!!!input$dependent, new_role = "outcome") %>%
update_role(!!!input$indep, new_role = "predictor") %>%
prep() %>%
formula()
})
lm_reg <- reactive(
lm(recipe_formula(),data = mtcars)
)
output$RegOut = renderPrint({
summary(lm_reg())
})
}
# Run the application
shinyApp(ui = ui, server = server)