Movatterモバイル変換


[0]ホーム

URL:


Skip to contents

04. JavaScript

Colin Fay

2025-12-06

Source:vignettes/d-js.Rmd
d-js.Rmd

Using{golem} js functions

golem comes with a series of JavaScript functions thatyou can call from the server. These functions are added by default withbundle_resources() .

Then they are called withgolem::invoke_js("fonction", "ui_element").

Thisui_element define the UI element to interact with.It can be a full jQuery selector, an id or a class. Note that you canadd several elements and iterate other them.

invoke_js can be used with any function defined in aJavaScriptCustom Handler, that you can build withgolem::add_js_handler().

golem::invoke_js()

  • showid &hideid,showclass &hideclass show and hideelements through their id or class.
golem::invoke_js("showid",ns("plot"))
  • showhref &hidehref hide and show alink by trying to match thehref content.
golem::invoke_js("showhref","panel2")
  • clickon click on the element. You have to use thefull jQuery selector.

  • show &hide show and hide elements,using the full jQuery selector.

  • disable &reable able and disablespecific element, using the full jQuery selector.

See?golem::activate_js() for the full list.

A quick intro to jQuery selectors

  • #plop: the element with the idplop

  • .pouet: elements of classpouet

  • "button:contains('this')": buttons with a textcontaining'this'

Note that in html, tags contains attributes. For example:

<a href="https://thinkr.fr" data-value="panel2">ThinkR</a>

containshref &data-value. You canrefer to these attributes with[] after the tag name.

  • a[href = "https://thinkr.fr"]: link withhref beinghttps://thinkr.fr

  • a[data-value="panel2"]: link withdata-value being"panel2"


[8]ページ先頭

©2009-2025 Movatter.jp