TL;DR: When running my R shiny app online, the dates are sorted correctly. When deploying the same app to shinyapps.io, the sorting of the date gets messed up. I have compared package versions between my local and online R instance, and they seem to be identical. Why are the two instances different?
Data ordering is done by creating a separate factor. Specifically, it was performed as follows:
I know it's not ideal, but one way to troubleshoot this is to print off some information about df_sorted prior to turning it into a factor variable, uploading your app, and then looking at what it prints out in the shinyapps.io logs. Comparing the logs to what the app prints off locally should give you an idea of what's causing (or not causing) your issues.
There's probably an easier way but that's how I'd start debugging this. You could print(str(df_sorted)) and print(unique(df_sorted$Date)) to start. Also, print(levels(df_sorted$Date)) after turning it into a factor variable might be helpful.
When running the print statements, I learned that already the first one, print(str(df_sorted)), leads to a different sorting between the web application and my own.
Any ideas why this could be? I don't see any problem with my first statement.
It's hard to know for sure without a reproducible example. Can you create a reprex from the data and processing portion of the script?
Are you running the app locally from a clean environment?
It could be that the local app is reading df_sorted$Date into ggplot as an ordered factor because it exists in that format in your local environment. The app on shinyapps.io is running from a clean environment, so df_sorted$Date might be being treated as a character vector - hence, why it's not being ordered in the figure. This implies that your code to process the character vector into an ordered factor isn't working, but also isn't throwing errors. You could test this by writing print(class(df_sorted$Date)) into the script right before the ggplot function runs.
That's my best guess without a reprex to work with!