Hello,
I am preparing Regression calculator in shiny.Please find below code for your refer.
ui <- fluidPage(
shinyFeedback::useShinyFeedback(),
sidebarLayout(
sidebarPanel(
helpText("Upload Data"),
fileInput("file", NULL, accept = c(".csv"), placeholder = ".csv file only"),
selectInput("independ.variable", "Select Independent Variables[ x1, x2, ..]", choices = NULL, multiple = T),
selectInput("depend.variable", "Select Dependent Variable[y]", choices = NULL)
),
mainPanel(
verbatimTextOutput("summary"),
tableOutput("table"),
verbatimTextOutput("model")
)
)
)
server <- function(input, output, session) {
reactive_dataset <- reactive({
req(input$file)
ext <- tools::file_ext(input$file$name)
switch(ext, csv = vroom::vroom(input$file$datapath, delim = ","),
validate("Invalid File; Please select .csv file"))
})
output$summary <- renderPrint({ summary(reactive_dataset())})
observeEvent(reactive_dataset(),{
choices <- colnames(reactive_dataset())
updateSelectInput(session, "independ.variable", choices = choices)
})
observeEvent(reactive_dataset(), {
choices <- colnames(reactive_dataset())
updateSelectInput(session, "depend.variable", choices = choices)
})
reactive_dataframe <- reactive({
req(input$independ.variable, input$depend.variable)
reactive_dataset() %>%
select(input$independ.variable, input$depend.variable)
})
output$table <- renderTable(head(reactive_dataframe()))
output$model <- renderPrint({
result <- reactive_dataframe() %>% map(~lm(input$depend.variable ~ ., data = reactive_dataframe()))
summary(result)
})
}
However i am getting "Error in model frame default variable lengths differ" in output$model.
Any suggestion, help will be appreciated !!