Due to the nature of the data, I can't share source data to run the code with.
So I started this mostly out of curiosity of what it would like to thumb through these models. My goal is just to look at a lot of regression models quickly so if there is a better way to do this, I'm open to another approach. I receive the error below when running the attached code.
I'm trying to generate linear regression models for renal patients with different stages of chronic kidney disease (CKD) end-stage renal disease (ESRD). I want to generate a linear model for CKD group that examines the relationship where x= visit count and y = Total amount paid
Listening on http://127.0.0.1:3516
Warning: Error in $: Can't read output 'plot'
46: <Anonymous>
45: signalCondition
44: signal_abort
43: rlang::abort
42: $.shinyoutput
40: server [#2]
3: runApp
2: print.shiny.appobj
1: <Anonymous>
Error in output$plot : Can't read output 'plot'
# Load necessary libraries
library(ggplot2)
library(shiny)
library(dplyr)
library(readxl)
library(stringr)
# Load & Rename data
Kidney_Correlations_Data <- read_excel("Kidney Correlations Data.xlsx")
Kidney_Correlations_Data <- as.data.frame(Kidney_Correlations_Data) %>%
mutate(
CKD_STAGE = str_replace(Kidney_Correlations_Data[[3]], "CKD 3.*", "CKD 3")
)
# Create a reactive function to filter the data based on user input
ckd_condition <- reactive({
input$condition
})
visit_threshold <- reactive({
input$visit_threshold
})
filtered_data <- reactive({
Kidney_Correlations_Data %>%
filter(CKD_STAGE == ckd_condition, VISIT_COUNT > visit_threshold)
})
# Create a linear model and visualization
output$plot <- renderPlot({
validate(
need(input$condition != "", "Please select a condition"),
need(input$visit_threshold > 0, "Please enter a valid visit threshold")
)
# Filter the data based on the user's input
data <- filtered_data()
# Create a linear model
lm_model <- lm(Sum_Sum_MR_ALLOWED ~ VISIT_COUNT, data = data)
# Create a plot of the linear model
ggplot(data, aes(x = VISIT_COUNT, y = Sum_Sum_MR_ALLOWED)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Visit Count", y = "Paid Amount")
})
# Create a dropdown menu for the user to select the CKD condition level
# and a numeric input field for the visit threshold
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("condition", "Select CKD Condition:", c("CKD 3", "CKD 4", "CKD 5", "ESRD")),
numericInput("visit_threshold", "Minimum Visit Count:", value = 5, min = 0)
),
mainPanel(
plotOutput("plot")
)
)
)
# Run the application
shinyApp(ui = ui, server = function(input, output) {
output$plot
})