rstudio / shiny

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

RenderPlot() not showing/updating on Shiny Flexdashboard #3684

Closed ranjiGT closed 2 years ago

ranjiGT commented 2 years ago

I am having trouble using renderPlot()reactive function to update my plot on Flexdashboard.

System details

Browser Version:

Output of sessionInfo():

> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

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_1.7.1         viridis_0.6.2       viridisLite_0.4.0   htmltools_0.5.2    
 [5] forcats_0.5.1       purrr_0.3.4         tibble_3.1.7        tidyverse_1.3.1    
 [9] flexdashboard_0.5.2 lubridate_1.8.0     syuzhet_1.0.6       sentimentr_2.9.1   
[13] widyr_0.1.4         tm_0.7-8            NLP_0.2-1           gt_0.6.0           
[17] tidyr_1.2.0         tidytext_0.3.3      igraph_1.3.1        stringi_1.7.6      
[21] stringr_1.4.0       ggraph_2.0.5        ggplot2_3.3.6       magrittr_2.0.3     
[25] highcharter_0.9.4   readr_2.1.2         dplyr_1.0.9        

loaded via a namespace (and not attached):
 [1] colorspace_2.0-3   slider_0.2.2       ellipsis_0.3.2     qdapRegex_0.7.5   
 [5] fs_1.5.2           rstudioapi_0.13    listenv_0.8.0      furrr_0.3.0       
 [9] farver_2.1.0       graphlayouts_0.8.0 SnowballC_0.7.0    ggrepel_0.9.1     
[13] fansi_1.0.3        textclean_0.9.3    xml2_1.3.3         codetools_0.2-18  
[17] knitr_1.39         polyclip_1.10-0    rlist_0.4.6.2      jsonlite_1.8.0    
[21] broom_0.8.0        dbplyr_2.1.1       ggforce_0.3.3      compiler_4.2.0    
[25] httr_1.4.3         backports_1.4.1    assertthat_0.2.1   Matrix_1.4-1      
[29] fastmap_1.1.0      cli_3.3.0          later_1.3.0        tweenr_1.0.2      
[33] tools_4.2.0        gtable_0.3.0       glue_1.6.2         Rcpp_1.0.8.3      
[37] slam_0.1-50        cellranger_1.1.0   lexicon_1.2.1      vctrs_0.4.1       
[41] xfun_0.31          globals_0.15.0     stopwords_2.3      rvest_1.0.2       
[45] mime_0.12          lifecycle_1.0.1    future_1.26.1      MASS_7.3-57       
[49] zoo_1.8-10         scales_1.2.0       tidygraph_1.2.1    promises_1.2.0.1  
[53] hms_1.1.1          parallel_4.2.0     yaml_2.3.5         quantmod_0.4.20   
[57] curl_4.3.2         gridExtra_2.3      sass_0.4.1         tokenizers_0.2.1  
[61] checkmate_2.1.0    TTR_0.24.3         warp_0.2.0         commonmark_1.8.0  
[65] rlang_1.0.2        pkgconfig_2.0.3    evaluate_0.15      lattice_0.20-45   
[69] labeling_0.4.2     htmlwidgets_1.5.4  tidyselect_1.1.2   parallelly_1.31.1 
[73] R6_2.5.1           generics_0.1.2     DBI_1.1.2          pillar_1.7.0      
[77] haven_2.5.0        withr_2.5.0        xts_0.12.1         textshape_1.7.3   
[81] janeaustenr_0.1.5  modelr_0.1.8       crayon_1.5.1       utf8_1.2.2        
[85] tzdb_0.3.0         rmarkdown_2.14     grid_4.2.0         readxl_1.4.0      
[89] data.table_1.14.2  reprex_2.0.1       digest_0.6.29      xtable_1.8-4      
[93] httpuv_1.6.5       munsell_0.5.0     

Describe the problem in detail

I have the following code:

selectInput("select_cc", 
            label = "Select Course", 
            choices = c("imdb2012", "imdb2013", 'imdb2014','imdb2015',"internetworking","intsec2016",
                        "sql", "www", "internetworking2014", "bpm2013", 'internetworking2013', "bpm2016", 'insights-2016', 'ehealth2016', 'ws-privacy2016', 'bpm2019', 'designthinking2019', 'digital_entrepreneurship2021', 'intsec2014'))

    actionButton("synergy", "Update", 
                 class = "btn btn-primary")

    hr()

This gives me:

Screenshot 2022-08-14 at 21 51 55

And I have the following code which should dynamically change the plot using the below:

renderPlot({
  input$synergy
  df_PR_date %>%
  arrange(ymd(date)) %>% 
  filter(course_code == isolate(input$select_cc)) %>% 
  hchart("scatter", hcaes(x = date, y = ave_sentiment, group = Class)) %>% 
          hc_xAxis(title = list(text = "Years discussions were active in the forum")) %>%
          hc_yAxis(title = list(text = "Synergy levels")) %>% 
  hc_tooltip(pointFormat ="<b> Synergy score: </b> {point.y} <br>") %>% 
  hc_title(text = "Evolution of User Synergy Levels")
})

But it does not renders this plot

Screenshot 2022-08-14 at 21 54 26

I presume this is a bug. I have checked hard-coding the variable in my R studio, and it works. But on the dashboard, it does not.

nir4most commented 2 years ago

My advice is that should try to provide a reprex so that in principle someone could run your code on their system. Here is a link to a simple guide. https://community.rstudio.com/t/faq-how-to-do-a-minimal-reproducible-example-reprex-for-beginners/23061

cpsievert commented 2 years ago

You need to replace renderPlot() with highcharter::renderHighchart()