I'm encountering a bit of an error I can't explain, I've got a bs_carousel using the bsplus library. A working version of it is of this pattern:
bs_carousel("info") %>% bs_set_data(interval = FALSE) %>%
bs_append(bs_carousel_image(image1, if(checker1 == 1){reactable(df1[,!(names(df1) %in% c("Day"))])}))%>%
bs_append(bs_carousel_image(image2, if(checker2 == 1){reactable(df2[,!(names(df2) %in% c("Day"))])}))%>%
bs_append(bs_carousel_image(image3, if(checker3 == 1){reactable(df3[,!(names(df3) %in% c("Day"))])}))
However I need to put another condition in that shows each "bs_append" when a condition is met:
bs_carousel("info") %>% bs_set_data(interval = FALSE) %>%
if(dim(df1_checked)[1] != 0){bs_append(bs_carousel_image(image1, if(checker1 == 1){reactable(df1[,!(names(df1) %in% c("Day"))])}))}%>%
if(dim(df2_checked)[1] != 0){bs_append(bs_carousel_image(image2, if(checker2 == 1){reactable(df2[,!(names(df2) %in% c("Day"))])}))}%>%
if(dim(df3_checked)[1] != 0){bs_append(bs_carousel_image(image3, if(checker3 == 1){reactable(df3[,!(names(df3) %in% c("Day"))])}))}
However for some reason, I get the following error:
Error in if (.) dim(df1_checked)[1] != 0 else { :
argument is not interpretable as logical
I don't think it's a data issue (therefore I haven't posted it yet), because when I put the entire bs_carousel in the same condition, it runs fine (or at least correctly for that conidition):
if(dim(df1_checked)[1] != 0){
bs_carousel("info") %>% bs_set_data(interval = FALSE) %>%
bs_append(bs_carousel_image(image1, if(checker1 == 1){reactable(df1[,!(names(df1) %in% c("Day"))])}))%>%
bs_append(bs_carousel_image(image2, if(checker2 == 1){reactable(df2[,!(names(df2) %in% c("Day"))])}))%>%
bs_append(bs_carousel_image(image3, if(checker3 == 1){reactable(df3[,!(names(df3) %in% c("Day"))])}))}
Is my syntax wrong, or am I missing something more fundamental?
Thanks for any advice
CodePudding user response:
Not sure if this will get your end goal, but specific to your error message -- I believe this statement doesn't work because it's expecting an action after your "if" condition.
Try rewriting your logic in "if (.) dim(df1_checked)[1] != 0 else { :" to look like this psuedocode:
if (.) dim(df1_checked)[1] != 0{
<do stuff>}
else {
<do other stuff> }
CodePudding user response:
Was able to come up with a somewhat unsophisticated solution:
if(dim(df1)[1] != 0 & dim(df2)[1] != 0 & dim(df3)[1] != 0){
bs_carousel("info") %>% bs_set_data(interval = FALSE) %>%
bs_append(bs_carousel_image(image1, if(checker1 == 1){reactable(df1[,!(names(df1) %in% c("Day"))])}))%>%
bs_append(bs_carousel_image(image2, if(checker2 == 1){reactable(df2[,!(names(df2) %in% c("Day"))])}))%>%
bs_append(bs_carousel_image(image3, if(checker3 == 1){reactable(df3[,!(names(df3) %in% c("Day"))])}))}
if(dim(df1)[1] != 0 & dim(df2)[1] != 0 & dim(df3)[1] == 0){
bs_carousel("info") %>% bs_set_data(interval = FALSE) %>%
bs_append(bs_carousel_image(image1, if(checker1 == 1){reactable(df1[,!(names(df1) %in% c("Day"))])}))%>%
bs_append(bs_carousel_image(image2, if(checker2 == 1){reactable(df2[,!(names(df2) %in% c("Day"))])}))}
if(dim(df1)[1] != 0 & dim(df2)[1] == 0 & dim(df3)[1] == 0){
bs_carousel("info") %>% bs_set_data(interval = FALSE) %>%
bs_append(bs_carousel_image(image1, if(checker1 == 1){reactable(df1[,!(names(df1) %in% c("Day"))])}))}