Tuesday, 16 March 2021

How to eliminate or async render blocking scripts in R shiny?

I have a simple app, using only a couple of packages

library(shiny)
library(tableHTML)
library(shinyWidgets)
library(shinyFeedback)
library(lubridate)

Overall it is fast once loaded, but on a new session window it takes 3-4s.

When I analyse it on https://developers.google.com/speed/pagespeed/insights/ this is the main issue

Resources are blocking the first paint of your page. Consider delivering critical JS/CSS inline and deferring all non-critical JS/styles. Learn more.


URL
Transfer Size
Potential Savings
…shared/shiny.min.css()
1.9 KiB
180 ms
…css/shinyfeedback.css()
0.6 KiB
330 ms
…css/all.min.css()
12.7 KiB
630 ms
…css/v4-shims.min.css()
4.4 KiB
480 ms
…css/toastr.min.css()
3.1 KiB
330 ms
…shinyWidgets/shinyWidgets.min.css()
1.0 KiB
330 ms
…bootstrap-switch-3.3.4/bootstrap-switch.min.css()
1.4 KiB
180 ms
…css/bootstrap.min.css()
19.6 KiB
780 ms
…css/bootstrap-accessibility.min.css()
0.8 KiB
180 ms
…__assets__/shiny-server.css()
1.3 KiB
180 ms
…shared/jquery.min.js()
30.5 KiB
1,080 ms
…shared/shiny.min.js()
25.7 KiB
930 ms
…js/shinyfeedback.js()
2.9 KiB
180 ms
…js/toastr.min.js()
2.3 KiB
180 ms
…js/shinytoastr.js()
0.6 KiB
180 ms
…shinyWidgets/shinyWidgets-bindings.min.js()
6.1 KiB
330 ms
…bootstrap-switch-3.3.4/bootstrap-switch.min.js()
3.8 KiB
180 ms
…js/bootstrap.min.js()
11.0 KiB
480 ms
…js/bootstrap-accessibility.min.js()
4.3 KiB
330 ms
…__assets__/sockjs-0.3.4.min.js()
11.4 KiB
480 ms
…__assets__/shiny-server-client.min.js()
18.6 KiB
480 ms

From what I read on JS websites, the answer is to make this all async. Is there an option with R shiny?

see sample app


library(shiny)
library(tableHTML)
library(shinyWidgets)
library(shinyFeedback)
library(lubridate)


ui <- fluidPage(
              div(id = 'mainp',
                  
                  div(style = 'margin-bottom:30px;margin-top:10px; text-align:center',
                      span('My app', style = 'font-size:24px'),
                      tableHTML_output('mytable')
                      )
              )
)

server <- function(input, output, session) {
  
  output$mytable <- render_tableHTML({
    tableHTML(head(mtcars))
  })
  
}

shinyApp(ui = ui, server = server)


from How to eliminate or async render blocking scripts in R shiny?

No comments:

Post a Comment