m_button: Add button into viewer

Description Usage Arguments Details Value Examples

View source: R/button.R

Description

Add additional buttons to the viewer and pass in JavaScript functions to enable additional actions to be done when the button is clicked (such as styling changes to the model). You can also use css flex layout to control the layout of all added buttons.

Usage

1
2
3
4
5
6
7
8
m_button(
  id,
  name,
  label,
  func,
  align_items = "flex-start",
  justify_content = "flex-start"
)

Arguments

id

R3dmol id or a r3dmol object (the output from r3dmol()).

name

Name for button.

label

Label for button.

func

The function executed when the button is clicked.

align_items

The css align-items property specifies the default alignment for items inside the viewer.

justify_content

The css justify-content property aligns the buttons when the items do not use all available space on the main-axis (horizontally).

Details

If more than one button is set, only the layout (justify-content and align-items) of the first button will be used.

Value

R3dmol id or a r3dmol object (the output from r3dmol())

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
library(r3dmol)

r3dmol() %>%
  m_add_model(data = pdb_1j72, format = "pdb") %>%
  m_zoom_to() %>%
  m_button(
    name = "cartoon",
    label = "Cartoon",
    align_items = "flex-end",
    justify_content = "center",
    func = "
      function() {
        viewer.setStyle({cartoon:{}});
        viewer.render();
      }
    "
  ) %>%
  m_button(
    name = "stick",
    label = "Stick",
    func = "
      function() {
        viewer.setStyle({stick:{}});
        viewer.render();
      }
    "
  )

r3dmol documentation built on March 14, 2021, 5:08 p.m.