JohnCoene / javascript-for-r-comments

1 stars 0 forks source link

HTML Element #19

Open MayaGans opened 3 years ago

MayaGans commented 3 years ago

Based on section 6.3, I thought I could create a *_html function to include an htmltools::htmlDependency() of my own custom css and javascript files:

myWidget_html <- function(...){
  htmltools::tagList(
    htmltools::htmlDependency(
      name    = "myWidget",
      version = utils::packageVersion("myWidget"),
      package = "myWidget",
      src     = "js/my_script.js",
      stylesheet = "css/my_css.css"
    ),
    htmltools::tags$div(..., class="calendar")
  )
}

Using the inspector I see the class has been applied (cool!) but the style sheet and js file are not rendering. Is this not where I need to put these files?

Related:

I created a folder called js and a folder called css that live inside the htmlwidgets folder - is this where it's customary to put those scripts?

Might be worth talking about this somewhere since I'm struggling to figure it out... Thanks!

MayaGans commented 3 years ago

Update:

I just put the name of my widget as the dependency name, used my package version, and included the script and style sheet files in the dependency yaml and that worked! Maybe when you introduce the YAML file you can talk about how that is also where you'd include your custom scripts?

  - name: myWidget
    version: 1.0.0
    src: htmlwidgets
    script: js/my_script.js
    stylesheet: css/my_css.css