Hi all
I am working on a Shiny app. It worked fine untill today. I didn't changed something on it.
When I want to visualize a ggplot, it give this error:
Error in as.POSIXlt.numeric: 'origin' must be supplied
But I don't use that function in my code. I use some hms function of lubridate, but still I cannot find the problem:
This is how I try to visualize my ggplot:
observeEvent(input$import, {
file1 <- input$import
server_data <- read.delim(file=file1$datapath, header = TRUE, na.strings=c(""," ","NA"))
#Create a subset of the data to remove/exclude the unnecessary columns:
subset_data_server <- server_data[,c(-5:-7,-9,-17,-25:-31)]
#Remove the rows with blank/NA values:
df1 <- na.omit(subset_data_server)
#The difference between the ResultTime and the FirstScanTime is the turn around time:
df1$TS_start <- paste(df1$FirstScanDate, df1$FirstScanTime)
df1$TS_end <- paste(df1$ResultDate, df1$ResultTime)
df1$TAT <- difftime(df1$TS_end,df1$TS_start,units = "mins")
updateSelectizeInput(session, 'test', choices = df1$TestName, server = TRUE)
output$barplot1 <- renderPlot({
if (input$test!=""){
df1_filtered <- df1[df1$TestName == input$test,]
#Calculate the amount of Result-samples each hour:
df2 <- as.data.frame(hour(hms(df1_filtered$ResultTime)))
df_aggr_Result <- aggregate(df2, by=list(df2$`hour(hms(df1_filtered$ResultTime))`), FUN = length)
#Renaming
names(df_aggr_Result)[names(df_aggr_Result) == "Group.1"] <- "hour"
names(df_aggr_Result)[names(df_aggr_Result) == "hour(hms(df1_filtered$ResultTime))"] <- "amount of samples"
all_h <- tibble(hour = 0:23)
df_plot = merge(x=all_h,y=df_aggr_Result,by="hour",all=TRUE)
df_plot[is.na(df_plot)] <- 0
ggplot(df_plot, aes(x = hour, y = `amount of samples`)) +
geom_bar(fill = "#0073C2FF", stat = "identity") +
theme(axis.text.x = element_text(face = "bold", color = "#993333", size = 15),
axis.text.y = element_text(face = "bold", color = "#993333", size = 15),
axis.line = element_line(color = "#993333", size = 1)) +
scale_x_continuous(breaks=seq(0,23,1)) +
xlab("Hours in a day") + ylab("Amount of samples")
}
})
First I upload the datafile and perform some filters and subsetting on, the step before the ggplot, I split the timestamp from eg 13:39:24 to 13 hours. This is aggregated/counted and placed in a dataframe that is visualized in the ggplot.
Who can I solve this problem?
Thanks in advance!