I'm trying to create an interactive shiny app in R that changes when you select a different "assignment group". The plot is a density chart that tracks the resolution time of a case (works fine outside of the app).
Why does the density plot not show up when I run the app?
I am not sure where the problem is, but when I try to run the app, the plot never renders and the select on the side panel shows multiple entries for the same group (I just want one for each group)...and R crashes half the time.
The app won't crash if I use a smaller data set (1000 rows, 3 columns), but is there a way for me to improve the code so that it runs with my dataset(about 50,000 rows and 3 columns)?
Unfortunately, I cannot share the actual data, but here's mock data I generated and tested--same issues only R doesn't crash because it's a smaller data set. The code below will run, but in the app, I only see the key--no chart, and the scaling does not refit when you resize the window;
Here's the code;
library(shiny)
library(ggplot2)
trax_cond <- data.frame(
id = 1:6,
Assigned_Group3 = c("District of Columbia", "Ohio", "Oklahoma", "Tennessee", "Tennessee", "New York"),
Total.Time.Days = c(5.9, 9.1, 7.8, 3, 8.3, 12.2)
)
#check variable class in each column
sapply(trax_cond, class)
trax_cond$Assigned_Group3 <- as.factor(trax_cond$Assigned_Group3)
trax_list <- as.list(trax_cond)
ui <- fluidPage(
sidebarPanel(
selectInput(inputId = "Assigned_Group3", label = "Assigned Groups:", choices = trax_list$Assigned_Group3),
mainPanel(
tags$h1("Density Plot"),
plotOutput("P1")
)
)
)
###
server <- function(input, output){
selectedData <- reactive({
trax_cond[,trax_cond$Assigned_Group3]
})
output$P1 <- renderPlot({
library(ggplot2)
qplot(Total.Time.Days, data=trax_cond, geom="density", fill=Assigned_Group3, alpha=I(.5),
main="Distribution Days to Resolve", xlab="Resolution Time (Days)",
ylab="Density")
})
}
shinyApp(ui,server)
and if I resize the window the output is cut off
How can I fix the issues, and make sure the output resizes when you resize the window?