Function Repository Resource:

 CellEvaluationButton

Source Notebook

Make a button that evaluates a set of cells when clicked

Contributed by: Jesse Friedman

ResourceFunction["CellEvaluationButton"][label,{obj1,obj2,…}]

creates a button that is labeled with label, and evaluates the cell objects obji when clicked.

ResourceFunction["CellEvaluationButton"][label]

prompts the user to select one or more cells.

Details and Options

When supplying a list of cells, the obji must be CellObject expressions.
ResourceFunction["CellEvaluationButton"][] is equivalent to ResourceFunction["CellEvaluationButton"]["Evaluate"].
ResourceFunction["CellEvaluationButton"][{obj1,obj2,…}] is equivalent to ResourceFunction["CellEvaluationButton"]["Evaluate", {obj1,obj2,…}].
ResourceFunction["CellEvaluationButton"][obj] is equivalent to ResourceFunction["CellEvaluationButton"][{obj}].
ResourceFunction["CellEvaluationButton"] has the same options as Button, with the following additions and changes:
AutoScrollFalsewhether to scroll the first targeted cell into view when the button is clicked
"ConfirmationPrompt"Nonethe text of a yes/no confirmation prompt displayed upon clicking the button, prior to evaluating the targeted cells
Method"Queued"the evaluation method to use
Setting the option AutoScroll→True will cause closed cell groups to open upon clicking the button as needed to display the targeted cells.
The option "ConfirmationPrompt" may have as its value either a string or Automatic, which is equivalent to "ConfirmationPrompt"→"Are you sure you want to perform this action?"
With Method→"Preemptive", confirmation prompts will fail to display, as dialog boxes are not supported within preemptive evaluations.
ResourceFunction["CellEvaluationButton"] cannot target cells in a notebook other than that in which it is evaluated.
ResourceFunction["CellEvaluationButton"] adds a cell tag of the form "CellEvaluationButton-<UUID>" to each of the targeted cells.
The Button returned by ResourceFunction["CellEvaluationButton"] may be freely copied to different locations within its origin notebook while maintaining functionality.
As cell tags are copied with cells, copying and pasting a cell targeted by a button will cause the button to target both the original cell and the copy.
Cell tags can be manually added to and removed from cells with the Cell ▶ Cell Tags ▶ Add/Remove Cell Tags menu item.

Examples

Basic Examples (2) 

Create a button that evaluates a selected cell or set of cells:

In[1]:=
ResourceFunction["CellEvaluationButton"][]
Out[1]=

Create a button that evaluates a set of cells specified with a list of CellObject expressions:

In[2]:=
ResourceFunction[
 "CellEvaluationButton"][{CellObject[1], CellObject[2], CellObject[3],
   CellObject[4]}]
Out[2]=

Scope (2) 

Create a button that displays a confirmation prompt when clicked:

In[3]:=
ResourceFunction["CellEvaluationButton"][
 "ConfirmationPrompt" -> Automatic]
Out[3]=

Customize the appearance of the returned Button with the resource function RainbowText:

In[4]:=
ResourceFunction["CellEvaluationButton"][
 Nest[Framed, ResourceFunction["RainbowText"]["My Rainbow Button"], 2], Appearance -> None]
Out[4]=

Publisher

Jesse Friedman

Version History

  • 1.0.0 – 07 October 2019

Related Resources

License Information