Depending on the filter sometimes I end up with a chart with categories that don't have values in them because the filtered data frame I feed the function ends up looking like dat from my reprex. How do I exclude categories from appearing on the plot when the value is 0 or NA?
Thank you for the welcome. First post! long time reader. I didn't include the filter step to make the reprex more simplified because the whole thing is actually part of a bigger shiny renderPlotly function. The filter happens before the function and gets me the data frame I'm calling "dat" in the reprex. Then if you run the function like I have at the end of the reprex, get_plot(dat, a= c(1:5)) it results in a bar plot with 5 categories but the "one" category and the "five" category are empty. How do output the plot but not show the empty categories? Keeping in mind that I can't just drop category one and five because sometimes, depending on how the data that creates dat are filtered, there are values in those categories.
update, after thinking about it more this morning and doing more googling and trying things I figure out a solution. I inserted these select statements into the function and it gets me what I wanted!
p<- data %>%
select(where(~!any(is.na(.)))) %>%
select(where(~!any(.== 0))) %>%