add_script: Add external (JavaScript) scripts to a Dash app

Description Usage Arguments Examples

View source: R/wrappers.R

Description

Add external (JavaScript) scripts to a Dash app

Usage

1
add_script(app, script)

Arguments

app

A dash application created with dash_app()

script

A single script or a list of scripts. Each script is either a string (the URL), or a named list with src (the URL) and any other valid <script> tag attributes. See examples below. Note that this is only used to add external scripts, not local.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
app <- dash_app()

# Add a single script with URL
app %>% add_script("https://stackpath.bootstrapcdn.com/bootstrap/4.4.0/js/bootstrap.min.js")

# Add multiple scripts with URL
app %>% add_script(list(
  "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js",
  "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
))

# Add a single script with a list
app %>% add_script(
  list(
    href = "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js",
    integrity = "sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
  )
)

# Add multiple scripts with both URL and list
app %>% add_script(
  list(
    "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js",
    "https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js",
    list(
      href = "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js",
      integrity = "sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
    )
  )
)

dash documentation built on Nov. 7, 2021, 9:06 a.m.