How to write “function” or “if” with day, If my data does not exist every day. Shiny dashboard

Originally, the code that I’ve been trying to replicate, its data is about flights with any airlines. It means that original data, its transactions happened every day.**

But I would like to apply this code with my data which is about daily sales. However, sometimes, transaction of sales cannot be occurred every day.**

Because of this,

my shiny dashboard hasn’t shown data properly when I clicked day on a bar chart.**

For example, I clicked on second bar (day =4) of November as figure 1, and then it has shown nothing with day 2 as figure 2 (Because “day 2” does not include in my data.**

So, I would like to create some conditions that my dashboard can read date of my data.**

I would appreciate, if someone help me

Thank you so much.

Here this is my full code and data.

#Some part of this code

# Get details (server) --------------------------------------------
  get_details <- function(customer = NULL, day = NULL) {
    # Create a generic details function that can be called
    # by different dashboard events
    
    res <- base_electric() 
    
   
    if (!is.null(customer)) res <- filter(res, Customer == as.character(customer))
    if (!is.null(day)) res <- filter(res, day == !!as.integer(day))
    
    res %>%
      head(100) %>% 
      select(
        month, day, Customer, cust_name, Quantity, UnitPrice
        
      ) %>%
      collect() %>%
      mutate(month = month.name[as.integer(month)]) 
    
    
  }


Hi,

I'm not really sure what you want to do here...
It seems logical to me that if you click the bar and there is no sale for a particular day that the table is empty right? What would you like to happen or not happen in case there is no sale?

Also, providing your whole whole app is not the best way to convince folk to attack your issue, because it's very hard to read another person's code, especially since likely 99% is not part of the issue. Try and isolate the issue and recreate it in a small reprex, and you might have more chance that folk can quickly help you out. A reprex consists of minimal code and data needed to recreate the issue, omitting any other code. Shiny debugging and reprex guide

PJ

Thank for your reply.
1.If you click the bar and there is no sale for a particular day that the table is empty right? : No. Actually some days have sales when I clicked a bar(day) and then they have shown nothing.

And not ever day has sales that why I got this issue. May be I need to write some codes like if suctions to fix this?

2.What would you like to happen or not happen in case there is no sale?:
I would like to have the dashboard that shows information table when I click sales bar(day) as the attached picture.
But my problem, when I clicked some bars, they do not show anything.

Hi,

Although still not a real reprex, you do have a GitHub setup which at least made it a bit easier. Unfortunately the code is large and messy as I feared, but I was able to fix one of the issues:

In the server function where you grab the day from the bar plot clicked, I changed the following:

day <-input$column_clicked

to

day <- unique(base_electric()$day)[as.integer(input$column_clicked)]

The variable input$column_clicked returns the index of the bar clicked, not the actual day attached to it, so I fixed that and now it should work.

Another note: your data (GlRevenue and res112Ex) are not loaded properly into the app at start, so make sure you do that in the global script. I added the following

GlRevenue = readxl::read_xlsx("GlRevenue.xlsx")
res112Ex = read.csv("res112Ex.csv"

PJ

Thank you so so much. you saved my life. It works.
Do you mind if I ask another question? If I would like to group sales within one bar for one month as figure 1.

I need to change this part right?

grouped <- ifelse(input$month != 99, expr(day), expr(month))

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.