posit-dev / r-shinylive

https://posit-dev.github.io/r-shinylive/
Other
156 stars 16 forks source link

unable to find shiny modules, css, and js files exported with app #88

Closed seanbirchall closed 4 months ago

seanbirchall commented 4 months ago

I have a previous app that had no issue loading css / js dependencies using the below (app). I've noticed recently that this appears to no longer work. If I clone the above and run httpuv::runStaticServer("site") which is within apps\ide\site the app launches and doesn't show much out of the ordinary in the console for errors besides the below. However the app launches as a blank screen.

EDIT: The issue also exists with shiny modules too.

shinylive.js:34938 preload error:wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
_error @ shinylive.js:34938Understand this error
shinylive.js:34938 preload error:falling back to ArrayBuffer instantiation

App folder structure of previously working app

app_folder/
├── app.R
└── www/
    ├── style.css
    └── custom.js
└── R/
    ├── mod.R

Previously working code

# css
  shiny::tags$head(
    shiny::tags$link(
      rel = "stylesheet", href = "style.css"
    )
  )
# js
  shiny::includeScript(
    path = "www/custom.js"
  ) 

If I try different ways to include css / js I get different errors. For includeScript / includeCSS the shinylive app fails as it cannot find the files. For tags$script / tags$link the app launches but also cannot find the files mounted on localhost/style.css ... etc.

Smaller reprex app trying various ways to include css / js (same folder structure).

library(shiny)
library(bslib)

ui <- bslib::page(

  # title needs to be edited in webR/index.html
  title = "WebR IDE",

  # base style
  theme = bslib::bs_theme(
    preset = "flatly",
    font_scale = 0.95,
    `enable-rounded` = FALSE,
    `enable-transitions` = FALSE
  ),

  # style
  shiny::tags$head(
    shiny::tags$link(
      rel = "stylesheet", type = "text/css", href = "style.css"
    )
    # shiny::includeCSS(
    #   "www/style.css"
    # ),
    # shiny::includeCSS(
    #   system.file(
    #     "www/style.css"
    #   )
    # )
  ),

  # content
  bslib::card(
    class = "main-container",
    full_screen = FALSE,
    fill = TRUE,
    "something",
    ui_mod(
      id = "mod"
    )
  ),

  # javascript
  shiny::includeScript(
    path = "https://cdnjs.cloudflare.com/ajax/libs/split.js/1.6.2/split.min.js"
  )
  # shiny::includeScript(
  #   path = "www/split.min.js"
  # ),
  # shiny::includeScript(
  #   system.file(
  #     "www/split.min.js"
  #   )
  # )

)

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

  server_mod(
    id = "mod"
  )

}

shinyApp(ui = ui, server = server)

I can however include css / js from a remote URL like below. After messing with it for quite a bit I thought it'd be something related to my browser cache or an outdated version of shinylive, but it looks like this could be an new unintended bug.

shiny::includeScript(
    path = "https://cdnjs.cloudflare.com/ajax/libs/split.js/1.6.2/split.min.js"
  )

I probably need to get my R package version updated to 0.1.1.9000 and web assets to 0.3.0

# current assets
shinylive::assets_info()
shinylive R package version:  0.1.1
shinylive web assets version: 0.2.3

# updating fails need to mess around with this more
pak::pak("posit-dev/r-shinylive")

→ Will update 1 package.
→ Will download 1 package with unknown size.
+ shinylive 0.1.1 → 0.1.1.9000 [bld][cmp][dl] (GitHub: 097a7b8)

! shinylive is loaded in the current R session, you probably need to restart R after the installation.

? Do you want to continue (Y/n) Y
ℹ Getting 1 pkg with unknown size
✔ Cached copy of shinylive 0.1.1.9000 (source) is the latest build
✔ No downloads needed, all packages are cached                      
ℹ Building shinylive 0.1.1.9000
Error:        
! error in pak subprocess
Caused by error: 
! Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
Type .Last.error to see the more details.
> .Last.error
<callr_error/rlib_error_3_0/rlib_error/error>
Error: 
! error in pak subprocess
Caused by error: 
! Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
---
Backtrace:
1. pak::pak("posit-dev/r-shinylive")
2. pak::pkg_install(pkg, ...)
3. pak:::remote(function(...) get("pkg_install_do_plan", asNamespace("pak"))(...), …
4. err$throw(res$error)
---
Subprocess backtrace:
 1. base::withCallingHandlers(cli_message = function(msg) { …
 2. get("pkg_install_do_plan", asNamespace("pak"))(...)
 3. proposal$install()
 4. pkgdepends::install_package_plan(plan, lib = private$library, num_workers = nw, …
 5. base::withCallingHandlers({ …
 6. pkgdepends:::start_task(state, task)
 7. pkgdepends:::start_task_build(state, task)
 8. pkgdepends:::make_build_process(path, pkg, tmp_dir, lib, vignettes, needscompilation, …
 9. pkgdepends:::withr_with_libpaths(c(tmplib, lib), action = "prefix", pkgbuild::pkgbuild_process$new(path, …
10. base::force(code)
11. pkgbuild::pkgbuild_process$new(path, tmp_dir, binary = binary, …
12. local initialize(...)
13. pkgbuild:::rcb_init(self, private, super, path, dest_path, binary, vignettes, …
14. pkgbuild:::build_setup(path, dest_path, binary, vignettes, manual, clean_doc, …
15. pkgbuild:::build_setup_binary(path, dest_path, args, needs_compilation)
16. pkgbuild::check_build_tools(quiet = TRUE)
17. base::stop("Could not find tools necessary to compile a package\n", …
18. | base::.handleSimpleError(function (e) …
19. global h(simpleError(msg, call))
AnthonyFucci commented 4 months ago

This is what we did on a recent project for css/js resources:

ui <- bslib::page_navbar(
  useShinyjs(),
  tags$head(
    tags$style(id = "myproject_css", HTML(paste(readLines("www/css/style.css", warn = F), collapse = "\n"))),
    tags$script(id = "myproject_js", HTML(paste(readLines("www/js/script.js", warn = F), collapse = "\n")))
  ),
...

This adds an id-named