rstudio / shiny

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

trying to render PNG image dashboard title: shinyApp() vs runApp() in shinyapps.io #3743

Closed matt-sd-watson closed 1 year ago

matt-sd-watson commented 1 year ago

System details

Browser Version:

Output of sessionInfo():

R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] cytosel_0.0.0.9000  plotly_4.10.1       reactable_0.3.0     printr_0.2          DT_0.26            
 [6] forcats_0.5.2       stringr_1.4.1       dplyr_1.0.10        purrr_0.3.5         readr_2.1.3        
[11] tidyr_1.2.1         tibble_3.1.8        ggplot2_3.4.0       tidyverse_1.3.2     yaml_2.3.6         
[16] rsconnect_0.8.28    BiocManager_1.30.19 shiny_1.7.3         testthat_3.1.5     

loaded via a namespace (and not attached):
  [1] pbapply_1.6-0               lattice_0.20-45             haven_2.5.1                
  [4] vctrs_0.5.1                 expm_0.999-6                V8_4.2.2                   
  [7] usethis_2.1.6               survival_3.4-0              prodlim_2019.11.13         
 [10] spatstat.data_3.0-0         later_1.3.0                 DBI_1.1.3                  
 [13] SingleCellExperiment_1.20.0 uwot_0.1.14                 xopen_1.0.0                
 [16] dqrng_0.3.0                 rdrop2_0.8.2.1              zlibbioc_1.44.0            
 [19] fontawesome_0.4.0           htmlwidgets_1.5.4           future_1.29.0              
 [22] leiden_0.4.3                parallel_4.2.2              scater_1.26.1              
 [25] irlba_2.3.5.1               Rcpp_1.0.9                  KernSmooth_2.23-20         
 [28] promises_1.2.0.1            gdata_2.18.0.1              DelayedArray_0.24.0        
 [31] limma_3.54.0                pkgload_1.3.2               clusterGeneration_1.3.7    
 [34] debugme_1.1.0               fs_1.5.2                    textshaping_0.3.6          
 [37] brio_1.1.3                  fastmatch_1.1-3             mnormt_2.1.1               
 [40] basilisk_1.10.2             digest_0.6.30               png_0.1-8                  
 [43] bluster_1.8.0               sctransform_0.3.5           cowplot_1.1.1              
 [46] geneBasisR_0.0.0.9000       pkgconfig_2.0.3             spatstat.random_3.0-1      
 [49] DelayedMatrixStats_1.20.0   gower_1.0.0                 ggbeeswarm_0.6.0           
 [52] yardstick_1.1.0             iterators_1.0.14            reticulate_1.26            
 [55] SummarizedExperiment_1.28.0 beeswarm_0.4.0              learnr_0.11.2              
 [58] xfun_0.35                   bslib_0.4.1                 zoo_1.8-11                 
 [61] tidyselect_1.2.0            webdriver_1.0.6             reshape2_1.4.4             
 [64] ica_1.0-3                   rcmdcheck_1.4.0             viridisLite_0.4.1          
 [67] optimParallel_1.0-2         pkgbuild_1.4.0              rlang_1.0.6                
 [70] jquerylib_0.1.4             reactR_0.4.4                glue_1.6.2                 
 [73] waldo_0.4.0                 RColorBrewer_1.1-3          RcppZiggurat_0.1.6         
 [76] registry_0.5-1              modelr_0.1.10               matrixStats_0.63.0         
 [79] ggcorrplot_0.1.4            MatrixGenerics_1.10.0       lava_1.7.0                 
 [82] ggsignif_0.6.4              recipes_1.0.3               labeling_0.4.2             
 [85] httpuv_1.6.6                class_7.3-20                BiocNeighbors_1.16.0       
 [88] webshot_0.5.4               jsonlite_1.8.3              XVector_0.38.0             
 [91] systemfonts_1.0.4           mime_0.12                   gridExtra_2.3              
 [94] packrat_0.8.1               stringi_1.7.8               paleotree_3.4.5            
 [97] processx_3.8.0              spatstat.sparse_3.0-0       scattermore_0.8            
[100] spatstat.explore_3.0-5      quadprog_1.5-8              hardhat_1.2.0              
[103] bitops_1.0-7                cli_3.4.1                   maps_3.4.1                 
[106] batchelor_1.14.0            heatmaply_1.4.0             data.table_1.14.6          
[109] timechange_0.1.1            rstudioapi_0.14             TSP_1.2-1                  
[112] inferorg_0.1.0              nlme_3.1-160                phangorn_2.10.0            
[115] scran_1.26.0                locfit_1.5-9.6              zellkonverter_1.8.0        
[118] listenv_0.8.0               sortable_0.4.6              miniUI_0.1.1.1             
[121] urlchecker_1.0.1            dbplyr_2.2.1                entropy_1.3.1              
[124] BiocGenerics_0.44.0         clustifyr_1.10.0            sessioninfo_1.2.2          
[127] readxl_1.4.1                lifecycle_1.0.3             timeDate_4021.106          
[130] commonmark_1.8.1            munsell_0.5.0               cellranger_1.1.0           
[133] codetools_0.2-18            coda_0.19-4                 Biobase_2.58.0             
[136] GenomeInfoDb_1.34.3         vipor_0.4.5                 lmtest_0.9-40              
[139] xtable_1.8-4                ROCR_1.0-11                 googlesheets4_1.0.1        
[142] scatterplot3d_0.3-42        abind_1.4-5                 farver_2.1.1               
[145] parallelly_1.32.1-9006      ResidualMatrix_1.8.0        RANN_2.6.1                 
[148] askpass_1.1                 pingr_2.0.2                 SeuratObject_4.1.3         
[151] GenomicRanges_1.50.1        RcppAnnoy_0.0.20            goftest_1.2-3              
[154] patchwork_1.1.2             profvis_0.3.7               cluster_2.1.4              
[157] future.apply_1.10.0         Seurat_4.3.0                dendextend_1.16.0          
[160] Matrix_1.5-3                ellipsis_0.3.2              prettyunits_1.1.1          
[163] shinyBS_0.61.1              lubridate_1.9.0             ggridges_0.5.4             
[166] googledrive_2.0.0           shinydashboard_0.7.2        reprex_2.0.2               
[169] rematch_1.0.1               shinyalert_3.0.0            igraph_1.3.5               
[172] fgsea_1.24.0                shinyjs_2.1.0               remotes_2.4.2              
[175] gargle_1.2.1                basilisk.utils_1.10.0       phytools_1.2-0             
[178] spatstat.utils_3.0-1        htmltools_0.5.3             utf8_1.2.2                 
[181] ModelMetrics_1.2.2.2        ggpubr_0.5.0                withr_2.5.0                
[184] scuttle_1.8.1               fitdistrplus_1.1-8          BiocParallel_1.32.3        
[187] randomcoloR_1.1.0.1         foreach_1.5.2               combinat_0.0-8             
[190] progressr_0.11.0            ragg_1.2.4                  rsvd_1.0.5                 
[193] ScaledMatrix_1.6.0          devtools_2.4.5              memoise_2.0.1              
[196] evaluate_0.18               tzdb_0.3.0                  callr_3.7.3                
[199] caret_6.0-93                ps_1.7.2                    curl_4.3.3                 
[202] fansi_1.0.3                 tensor_1.5                  edgeR_3.40.0               
[205] cachem_1.0.6                desc_1.4.2                  dqshiny_0.0.5              
[208] deldir_1.0-6                dir.expiry_1.6.0            showimage_1.0.0            
[211] metapod_1.6.0               rstatix_0.7.1               parsedate_1.3.1            
[214] ggrepel_0.9.2               rprojroot_2.0.3             tools_4.2.2                
[217] sass_0.4.4                  magrittr_2.0.3              RCurl_1.98-1.9             
[220] car_3.1-1                   ape_5.6-2                   xml2_1.3.3                 
[223] httr_1.4.4                  assertthat_0.2.1            rmarkdown_2.18             
[226] globals_0.16.2              R6_2.5.1                    nnet_7.3-18                
[229] gtools_3.9.4                statmod_1.4.37              beachmat_2.14.0            
[232] annotables_0.1.91           BiocSingular_1.14.0         splines_4.2.2              
[235] carData_3.0-5               colorspace_2.0-3            generics_0.1.3             
[238] stats4_4.2.2                base64enc_0.1-3             pillar_1.8.1               
[241] sp_1.5-1                    uuid_1.1-0                  GenomeInfoDbData_1.2.9     
[244] plyr_1.8.8                  gtable_0.3.1                rvest_1.0.3                
[247] zip_2.2.2                   knitr_1.41                  IRanges_2.32.0             
[250] fastmap_1.1.0               crosstalk_1.2.0             seriation_1.4.0            
[253] ca_0.71.1                   Rfast_2.0.6                 broom_1.0.1                
[256] shinytest_1.5.1             openssl_2.0.4               scales_1.2.1               
[259] filelock_1.0.2              backports_1.4.1             plotrix_3.8-2              
[262] S4Vectors_0.36.0            ipred_0.9-13                hms_1.1.2                  
[265] Rtsne_0.16                  polyclip_1.10-4             grid_4.2.2                 
[268] numDeriv_2016.8-1.1         lazyeval_0.2.2              bsplus_0.1.4               
[271] wesanderson_0.3.6           crayon_1.5.2                MASS_7.3-58                
[274] pROC_1.18.0                 sparseMatrixStats_1.10.0    roxygen2_7.2.2             
[277] viridis_0.6.2               rpart_4.1.19                compiler_4.2.2             
[280] spatstat.geom_3.0-3        

Example application or steps to reproduce the problem

app <- function(...) {
 dashboardPage(
dashboardHeader(title=span(img(src="app-logo.png", height = "70%", width = "75%"))
# extra app code
shinyApp(ui, server, ...)
}

In a separate app.R file in the main package directory, the following function call is made to deploy the application on shinyapps (here app is just the stand-in name for the package name):

app::app()

Describe the problem in detail

I am attempting to add an image as a PNG file for a title in my shiny app using the code above The image does not render when using shinyApp() to call the application, but does work when using runApp(app()), to wrap the function call to shinyApp() in runApp(), which has been documented here before.

The issue is that runApp() calls do not work with shinyapps as documented here, so I am not sure what options are available to me to be able to render these images in my shinyapps.io deployment.

In my current configuration, I have a function called app that bundles the UI and server components together using shinyApp(). The PNG image that I want to add is in a www directory in the base directory of the R package.

If there are any suggestions for how to proceed with being able to render PNG images for apps that will ultimately go to a shinyapps.io deployment, that would be greatly appreciated.

cpsievert commented 1 year ago

The PNG image that I want to add is in a www directory in the base directory of the R package.

I think what you actually want is to place the image under the inst folder (in a location like inst/assets/app-logo.png). Then you can explicitly mount that directory by doing shiny::addResourcePath("assets", system.file("assets", package = "app")). Just make sure you add the proper prefix to file paths (e.g., img(src="assets/app-logo.png")).

matt-sd-watson commented 1 year ago

Thanks for the recommendation! i was able to navigate around this by using imageOutput and renderImage for the dashboard title, but I may modify it to implement this way.