Basic ggboxplot is not getting displayed as per the filter

Not sure what wrong I am doing here, as per the selected filter the plots are not displayed. I have given a basic filter. Please guide. I have another way to do this and that code is working, But that takes long lines of code, So I thought this is the optimized one but not working

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(shiny)
library(tidyverse)
library(ggpubr)
library(ggplot2)
```

```{r}
df <- structure(list(ColA = c(39, 13, 16, 36), ColB = c("A", "A", "A", 
"A"), ColC = c(97, 83, 115, 141), ColD = c(91, 127, 78, 84), 
    ColE = c("E", "E", "E", "E"), ColF = structure(c(1569628800, 
    1569715200, 1569801600, 1569888000), class = c("POSIXct", 
    "POSIXt"), tzone = "UTC")), row.names = c(NA, 4L), class = "data.frame")
df <- df %>% mutate_if(is.character,as.factor)
df <- as.data.frame(df)
```
Factors
===============

Inputs {.sidebar}
-----------------------------------------------------------------------

```{r}
selectInput("F1","Factor1",choices = c("",names(Filter(is.factor,df))))
output$filter2 <- renderUI({
  if (input$F1 == "") {
    return()
  } else {
    label = "Numeric Variable to compare"
    selectInput("N",label,choices = c("",names(Filter(is.numeric,df))))
  } 
})
uiOutput("filter2")
radioButtons("T1","Tests",choices = c("t.test","Anova","Wilcoxon"),selected = NULL)
```

Column {data-width=1000}
-----------------------------------------------------------------------

### Chart A 

```{r}

plotOutput("p1")
output$p1 <- renderPlot({
  req(input$F1)
  req(input$N)
  if (!is.null(input$F1)) {
    ggboxplot(df ,x = input$F1, y = input$N,
          color = input$F1, palette = "jco",
          add = "jitter")
  }
})
```

The last output code I tried with this as well but not getting displayed. Also, I really want to master in R programming. Not sure what wring I am wrong I am doing in this code also

```{r}
fa <- names(Filter(is.factor, df))
nu <- names(Filter(is.numeric, df))
plotOutput("p1")
p1 <- reactive({
{ 
 for(i in fa)
 for(j in nu){
  req(input$F1)
  req(input$N)
  if (input$F1 == i & input$N == j) {
    p <- print(ggboxplot(df ,x = i, y = j,
          color = i, palette = "jco",
          add = "jitter"))
  }}}
})
output$p1<- renderPlot(
      { 
        p1()
      }
    )
```

In your example above, I see several issue.

I see a df object is used but no such object if define. I guess the structure(... at the start of your document is for that ? Is the assignement df <- just missing?

If I am right with the above, your df has no column, so Filter(is.factor,df) will get you nothing, and your filter in shiny will be empty. I find it odd...

Can you tell me if reprex needs to be improved or if I missed something ?

1 Like

Sorry. I have now added df to the code

With your new example, I can see the plot...

What is the issue exactly ?

1 Like

Strange . I am not a see the output in my system. Not sure. I have been trying to solve this issue since morning. Any idea why? Is it because of system issues?

How do you render the document ? I clicked on Run Document in RStudio.

Make sure that your YAML header has the correct indentations:

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---

I'm able to see the boxplot on my end so I have also included my packages info so you can check if you're on the same versions for the required packages.

Package info
package       * version    date       lib source                          
 assertthat      0.2.1      2019-03-21 [1] RSPM (R 3.5.2)                  
 backports       1.1.4      2019-04-10 [1] RSPM (R 3.5.2)                  
 base64enc       0.1-3      2015-07-28 [1] RSPM (R 3.5.0)                  
 BH              1.69.0-1   2019-01-07 [1] RSPM (R 3.5.2)                  
 broom           0.5.0      2018-07-17 [1] RSPM (R 3.5.0)                  
 callr           3.1.1      2018-12-21 [1] RSPM (R 3.5.0)                  
 cellranger      1.1.0      2016-07-27 [1] RSPM (R 3.5.0)                  
 cli             1.1.0      2019-03-19 [1] RSPM (R 3.5.2)                  
 clipr           0.5.0      2019-01-11 [1] RSPM (R 3.5.0)                  
 colorspace      1.3-2      2016-12-14 [1] RSPM (R 3.5.0)                  
 crayon          1.3.4      2017-09-16 [1] RSPM (R 3.5.0)                  
 crosstalk       1.0.0      2016-12-21 [1] RSPM (R 3.5.0)                  
 curl            3.2        2018-03-28 [1] RSPM (R 3.5.0)                  
 DBI             1.0.0      2018-05-02 [1] RSPM (R 3.5.0)                  
 dbplyr          1.3.0      2019-01-09 [1] RSPM (R 3.5.2)                  
 digest          0.6.21     2019-09-20 [1] RSPM (R 3.5.3)                  
 dplyr           0.8.3      2019-07-04 [1] RSPM (R 3.5.2)                  
 ellipsis        0.2.0.1    2019-07-02 [1] RSPM (R 3.5.2)                  
 evaluate        0.14       2019-05-28 [1] RSPM (R 3.5.2)                  
 fansi           0.4.0      2018-10-05 [1] RSPM (R 3.5.2)                  
 fastmap         1.0.1      2019-10-08 [1] RSPM (R 3.5.3)                  
 flexdashboard   0.5.1.1    2018-06-29 [1] RSPM (R 3.5.2)                  
 forcats         0.4.0      2019-02-17 [1] RSPM (R 3.5.2)                  
 fs              1.2.6      2018-08-23 [1] RSPM (R 3.5.0)                  
 ggplot2         3.2.0      2019-06-16 [1] RSPM (R 3.5.2)                  
 glue            1.3.1      2019-03-12 [1] RSPM (R 3.5.2)                  
 gridExtra       2.3        2017-09-09 [1] RSPM (R 3.5.2)                  
 gtable          0.2.0      2016-02-26 [1] RSPM (R 3.5.0)                  
 haven           2.1.0      2019-02-19 [1] RSPM (R 3.5.2)                  
 highr           0.8        2019-03-20 [1] RSPM (R 3.5.2)                  
 hms             0.4.2      2018-03-10 [1] RSPM (R 3.5.2)                  
 htmltools       0.4.0      2019-10-04 [1] CRAN (R 3.5.3)                  
 htmlwidgets     1.5.1      2019-10-08 [1] RSPM (R 3.5.3)                  
 httpuv          1.5.2      2019-09-11 [1] RSPM (R 3.5.3)                  
 httr            1.3.1      2017-08-20 [1] RSPM (R 3.5.0)                  
 jsonlite        1.6        2018-12-07 [1] RSPM (R 3.5.2)                  
 knitr           1.23       2019-05-18 [1] RSPM (R 3.5.2)                  
 labeling        0.3        2014-08-23 [1] RSPM (R 3.5.0)                  
 later           1.0.0      2019-10-04 [1] RSPM (R 3.5.3)                  
 lattice         0.20-38    2018-11-04 [2] CRAN (R 3.5.3)                  
 lazyeval        0.2.1      2017-10-29 [1] RSPM (R 3.5.0)                  
 leaflet         2.0.2      2018-08-27 [1] RSPM (R 3.5.2)                  
 lubridate       1.7.4      2018-04-11 [1] RSPM (R 3.5.0)                  
 magrittr        1.5        2014-11-22 [1] RSPM (R 3.5.0)                  
 markdown        1.0        2019-06-07 [1] RSPM (R 3.5.2)                  
 MASS            7.3-51.1   2018-11-01 [2] CRAN (R 3.5.3)                  
 Matrix          1.2-15     2018-11-01 [2] CRAN (R 3.5.3)                  
 mgcv            1.8-27     2019-02-06 [2] CRAN (R 3.5.3)                  
 mime            0.7        2019-06-11 [1] RSPM (R 3.5.2)                  
 modelr          0.1.4      2019-02-18 [1] RSPM (R 3.5.2)                  
 munsell         0.5.0      2018-06-12 [1] RSPM (R 3.5.0)                  
 nlme            3.1-137    2018-04-07 [2] CRAN (R 3.5.3)                  
 openssl         1.0.2      2018-07-30 [1] RSPM (R 3.5.0)                  
 pillar          1.4.2      2019-06-29 [1] RSPM (R 3.5.2)                  
 pkgconfig       2.0.2      2018-08-16 [1] RSPM (R 3.5.2)                  
 plogr           0.2.0      2018-03-25 [1] RSPM (R 3.5.0)                  
 plyr            1.8.4      2016-06-08 [1] RSPM (R 3.5.0)                  
 png             0.1-7      2013-12-03 [1] RSPM (R 3.5.2)                  
 processx        3.3.0      2019-03-10 [1] RSPM (R 3.5.2)                  
 promises        1.1.0      2019-10-04 [1] RSPM (R 3.5.3)                  
 ps              1.3.0      2018-12-21 [1] RSPM (R 3.5.0)                  
 purrr           0.3.2      2019-03-15 [1] RSPM (R 3.5.2)                  
 R6              2.4.0      2019-02-14 [1] RSPM (R 3.5.2)                  
 raster          2.8-19     2019-01-30 [1] RSPM (R 3.5.2)                  
 RColorBrewer    1.1-2      2014-12-07 [1] RSPM (R 3.5.0)                  
 Rcpp            1.0.2      2019-07-25 [1] CRAN (R 3.5.2)                  
 readr           1.3.1      2018-12-21 [1] CRAN (R 3.5.0)                  
 readxl          1.1.0      2018-04-20 [1] RSPM (R 3.5.0)                  
 rematch         1.0.1      2016-04-21 [1] RSPM (R 3.5.0)                  
 reprex          0.2.1      2018-09-16 [1] RSPM (R 3.5.0)                  
 reshape2        1.4.3      2017-12-11 [1] RSPM (R 3.5.0)                  
 rlang           0.4.0      2019-06-25 [1] RSPM (R 3.5.2)                  
 rmarkdown       1.14       2019-07-12 [1] RSPM (R 3.5.2)                  
 rstudioapi      0.10       2019-03-19 [1] RSPM (R 3.5.3)                  
 rvest           0.3.2      2016-06-17 [1] RSPM (R 3.5.0)                  
 scales          1.0.0      2018-08-09 [1] RSPM (R 3.5.0)                  
 selectr         0.4-1      2018-04-06 [1] RSPM (R 3.5.0)                  
 shiny           1.4.0      2019-10-10 [1] CRAN (R 3.5.3)                  
 sourcetools     0.1.7      2018-04-25 [1] RSPM (R 3.5.0)                  
 sp              1.3-1      2018-06-05 [1] RSPM (R 3.5.2)                  
 stringi         1.4.3      2019-03-12 [1] RSPM (R 3.5.2)                  
 stringr         1.4.0      2019-02-10 [1] RSPM (R 3.5.2)                  
 tibble          2.1.3      2019-06-06 [1] RSPM (R 3.5.2)                  
 tidyr           0.8.3.9000 2019-07-24 [1] Github (tidyverse/tidyr@d72baa7)
 tidyselect      0.2.5      2018-10-11 [1] RSPM (R 3.5.2)                  
 tidyverse       1.2.1      2017-11-14 [1] RSPM (R 3.5.2)                  
 tinytex         0.14       2019-06-25 [1] RSPM (R 3.5.2)                  
 utf8            1.1.4      2018-05-24 [1] RSPM (R 3.5.0)                  
 vctrs           0.2.0      2019-07-05 [1] RSPM (R 3.5.2)                  
 viridis         0.5.1      2018-03-29 [1] RSPM (R 3.5.2)                  
 viridisLite     0.3.0      2018-02-01 [1] RSPM (R 3.5.0)                  
 whisker         0.3-2      2013-04-28 [1] RSPM (R 3.5.0)                  
 withr           2.1.2      2018-03-15 [1] RSPM (R 3.5.0)                  
 xfun            0.8        2019-06-25 [1] RSPM (R 3.5.2)                  
 xml2            1.2.0      2018-01-24 [1] RSPM (R 3.5.0)                  
 xtable          1.8-2      2016-02-05 [1] RSPM (R 3.5.0)                  
 yaml            2.2.0      2018-07-25 [1] RSPM (R 3.5.0)                  
 zeallot         0.1.0      2018-01-28 [1] RSPM (R 3.5.2)
3 Likes

Thanks and let me check

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