rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.38k stars 1.86k forks source link

datable is not rendered #1415

Closed xtmgah closed 8 years ago

xtmgah commented 8 years ago

Hello, Here is my app, i don't know why ggplot allplot1, allplot2, and table alltbl1 were not rendered, however, after remove (DT::dataTableOutput("alltbl1")) from UI, everything is fine. So, Could you check something wrong or it is a bug from DT or shiny. thanks.

library(shiny)
library(tidyverse)
library(ggrepel)

load("resultp.RData",envir=.GlobalEnv)
#save(,resultp_ratio_all_others,,resultp_normalization_all_others,resultp_normalization_uacc,resultp_ratio_uacc, resultp_normalization_hek,resultp_ratio_hek, file = "resultp.RData")

ui <- shinyUI(fluidPage(theme = "united",
                        navbarPage("MPRA analysis",
                                   tabPanel("MPRA Info",
                                            htmltools::includeHTML("info.html")
                                   ),
                                   tabPanel("ALL experiments",
                                            tabsetPanel(
                                              tabPanel("Ratio",
                                                       plotOutput("allplot1",height = 1000),
                                                       br(),
                                                       plotOutput("allplot2",height = 1000),
                                                       br(),
                                                       DT::dataTableOutput("alltbl1")),
                                              tabPanel("Normalization",
                                                       plotOutput("allplot3",height = 1000),
                                                       br(),
                                                       plotOutput("allplot4",height = 1000),
                                                       br()
                                              ),
                                              tabPanel("Others")
                                            )
                                   ),
                                   tabPanel("UACC903 Only"),
                                   tabPanel("HEK293FT Only")

                        )

))

server <- shinyServer(function(input, output) {

  output$allplot1 <- renderPlot({
    datat3 <- resultp_ratio_all %>% filter(p.value< 10e-10 | abs(LFD)>log2(1.5))
    ggplot(resultp_ratio_all,aes(LFD,(-log10(p.value)),col=Color))+geom_point()+geom_vline(xintercept=c(-1,-2,1,2),linetype=2,col="gray80")+geom_hline(yintercept=c(2,3),linetype=2,col="gray80")+geom_text_repel(data=datat3,aes(label=Gene))+scale_color_manual("Significance",values = c("#e41a1c","#4daf4a","gray40"))+theme(legend.position="bottom", legend.box = "horizontal")
  },height = 1000)

  output$allplot2 <- renderPlot({
    datat3 <- resultp_ratio_all %>% filter(p.value< 10e-10 | abs(LFD)>log2(1.5))
    resultp_ratio_all %>% filter(p.value<0.05) %>% ggplot(aes(LFD,(log2(-log10(p.value))),col=Color))+geom_point()+geom_vline(xintercept=c(-1,-2,1,2),linetype=2,col="gray80")+geom_hline(yintercept=c(2,3),linetype=2,col="gray80")+geom_text_repel(data=datat3,aes(label=Gene))+scale_color_manual("Significance",values = c("#e41a1c","#4daf4a","gray40"))+theme(legend.position="bottom", legend.box = "horizontal")
  },height = 1000)

  output$alltbl1 <- DT::renderDataTable({
    resultp_ratio_all %>% select(-Color) %>% DT::datatable(filter = 'top',rownames = FALSE,extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = list('pageLength', 'csv', 'excel', 'pdf', 'print',list(extend = 'colvis')))) %>% DT::formatSignif(c(3:9,17:28), 5) %>% DT::formatStyle(c('p.value','p.adjust.BH','p.adjust.BY'), color = DT::styleInterval(c(0.01,0.05), c('red', 'purple', 'black'))) %>% DT::formatStyle('LFD', color = DT::styleInterval(c(-1,1), c('red', 'black', 'blue'))) %>% DT::formatStyle(c("totaltp_freq","wgs_freq"), color = DT::styleInterval(c(2,3), c('black', 'purple', 'red')))
  })

  output$allplot3 <- renderPlot({
    datat3 <- resultp_normalization_all %>% filter(p.value< 10e-10 | abs(LFD)>log2(1.5))
    ggplot(resultp_normalization_all,aes(LFD,(-log10(p.value)),col=Color))+geom_point()+geom_vline(xintercept=c(-1,-2,1,2),linetype=2,col="gray80")+geom_hline(yintercept=c(2,3),linetype=2,col="gray80")+geom_text_repel(data=datat3,aes(label=Gene))+scale_color_manual("Significance",values = c("#e41a1c","#4daf4a","gray40"))+theme(legend.position="bottom", legend.box = "horizontal")
  },height = 1000)

  output$allplot4 <- renderPlot({
    datat3 <- resultp_normalization_all %>% filter(p.value< 10e-10 | abs(LFD)>log2(1.5))
    resultp_normalization_all %>% filter(p.value<0.05) %>% ggplot(aes(LFD,(log2(-log10(p.value))),col=Color))+geom_point()+geom_vline(xintercept=c(-1,-2,1,2),linetype=2,col="gray80")+geom_hline(yintercept=c(2,3),linetype=2,col="gray80")+geom_text_repel(data=datat3,aes(label=Gene))+scale_color_manual("Significance",values = c("#e41a1c","#4daf4a","gray40"))+theme(legend.position="bottom", legend.box = "horizontal")
  },height = 1000)

})

# Run the application 
shinyApp(ui = ui, server = server)

#htmltools::tags$iframe(src = 'Promoter_GWAS_MPRA.html',frameborder="0", style="overflow: hidden; height: 100%; width: 100%; position: absolute;", height="100%", width="100%",scrolling="yes")

And here is my R session info:

> session_info()
Session info --------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, darwin13.4.0        
 ui       RStudio (0.99.903)          
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2016-10-10                  

Packages ------------------------------------------------------------------------------------
 package       * version date       source                           
 assertthat      0.1     2013-12-06 CRAN (R 3.3.0)                   
 BiocInstaller * 1.23.9  2016-09-04 Bioconductor                     
 colorspace      1.2-6   2015-03-11 CRAN (R 3.3.0)                   
 curl            2.1     2016-09-22 CRAN (R 3.3.0)                   
 DBI             0.5-1   2016-09-10 CRAN (R 3.3.0)                   
 devtools      * 1.12.0  2016-06-24 CRAN (R 3.3.0)                   
 digest          0.6.10  2016-08-02 CRAN (R 3.3.0)                   
 dplyr         * 0.5.0   2016-06-24 CRAN (R 3.3.0)                   
 DT            * 0.2     2016-08-09 CRAN (R 3.3.0)                   
 ggplot2       * 2.1.0   2016-03-01 CRAN (R 3.3.0)                   
 ggrepel       * 0.5     2016-02-08 CRAN (R 3.3.0)                   
 git2r           0.15.0  2016-05-11 CRAN (R 3.3.0)                   
 gtable          0.2.0   2016-02-26 CRAN (R 3.3.0)                   
 htmltools       0.3.5   2016-03-21 CRAN (R 3.3.0)                   
 htmlwidgets     0.7     2016-08-02 CRAN (R 3.3.1)                   
 httpuv          1.3.3   2015-08-04 CRAN (R 3.3.0)                   
 httr            1.2.1   2016-07-03 CRAN (R 3.3.0)                   
 jsonlite      * 1.1     2016-09-14 CRAN (R 3.3.0)                   
 labeling        0.3     2014-08-23 CRAN (R 3.3.0)                   
 lazyeval        0.2.0   2016-06-12 CRAN (R 3.3.0)                   
 magrittr        1.5     2014-11-22 CRAN (R 3.3.0)                   
 memoise         1.0.0   2016-01-29 CRAN (R 3.3.0)                   
 mime            0.5     2016-07-07 CRAN (R 3.3.0)                   
 munsell         0.4.3   2016-02-13 CRAN (R 3.3.0)                   
 plyr            1.8.4   2016-06-08 CRAN (R 3.3.0)                   
 purrr         * 0.2.2   2016-06-18 cran (@0.2.2)                    
 R.methodsS3     1.7.1   2016-02-16 CRAN (R 3.3.0)                   
 R.oo            1.20.0  2016-02-17 CRAN (R 3.3.0)                   
 R6              2.2.0   2016-10-05 CRAN (R 3.3.0)                   
 Rcpp            0.12.7  2016-09-05 CRAN (R 3.3.0)                   
 readr         * 1.0.0   2016-08-03 CRAN (R 3.3.0)                   
 rsconnect       0.4.3   2016-05-02 CRAN (R 3.3.0)                   
 scales          0.4.0   2016-02-26 CRAN (R 3.3.0)                   
 shiny         * 0.14.1  2016-10-10 Github (rstudio/shiny@c8a742a)   
 sourcetools     0.1.5   2016-09-15 CRAN (R 3.3.0)                   
 tibble        * 1.2     2016-08-26 cran (@1.2)                      
 tidyr         * 0.6.0   2016-08-12 CRAN (R 3.3.0)                   
 tidyverse     * 1.0.0   2016-09-26 Github (hadley/tidyverse@6e98d31)
 withr           1.0.2   2016-06-20 CRAN (R 3.3.0)                   
 xtable          1.8-2   2016-02-05 CRAN (R 3.3.0)                   
 yaml            2.1.13  2014-06-12 CRAN (R 3.3.0)                   
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] shiny_0.14.1         devtools_1.12.0      jsonlite_1.1         DT_0.2              
 [5] ggrepel_0.5          dplyr_0.5.0          purrr_0.2.2          readr_1.0.0         
 [9] tidyr_0.6.0          tibble_1.2           ggplot2_2.1.0        tidyverse_1.0.0     
[13] BiocInstaller_1.23.9

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7       git2r_0.15.0      plyr_1.8.4        R.methodsS3_1.7.1
 [5] tools_3.3.1       digest_0.6.10     memoise_1.0.0     gtable_0.2.0     
 [9] rstudioapi_0.6    DBI_0.5-1         curl_2.1          yaml_2.1.13      
[13] httr_1.2.1        withr_1.0.2       htmlwidgets_0.7   sourcetools_0.1.5
[17] grid_3.3.1        R6_2.2.0          magrittr_1.5      scales_0.4.0     
[21] htmltools_0.3.5   rsconnect_0.4.3   assertthat_0.1    mime_0.5         
[25] xtable_1.8-2      colorspace_1.2-6  httpuv_1.3.3      labeling_0.3     
[29] lazyeval_0.2.0    munsell_0.4.3     R.oo_1.20.0      
wch commented 8 years ago

Can you provide a minimal reproducible example? This means something that we would be able to run and test.

xtmgah commented 8 years ago

Hello:

Here is the minimal test. I think the app will working only excluded "htmltools::includeHTML("info.html")". Once it included, the figure and table will not rendered. Check it and let me know how to solve it. thanks.

test.zip

wch commented 8 years ago

I believe the problem is that the info.html file that you are including is a complete document, with its own and embedded scripts, which conflict with the ones that Shiny puts in the generated webpage. If you comment out the includeHTML("info.html"), everything else works.

You'll need to clean up the info.html file so that it's not a complete HTML document, but one that just has the content that needs to be embedded, or not embed the .html file at all.

xtmgah commented 8 years ago

OK. that what i am guessing. So, Is there any simple way to clean html files?

wch commented 8 years ago

You'll have to open it in a text editor and remove all the extra stuff.

xtmgah commented 8 years ago

Thanks.