Button beguiles me. A simple example follows:
b1 = Button["Evaluate", Cos[Pi/6], Method -> "Queued"] b2 = Button["Evaluate", Print[Cos[Pi/6]], Method -> "Queued"]
Both of the above statements produce buttons. When one clicks on
b1, it appears to evaluate something, but does not output or display anything. Clicking on
b2 displays the expected output.
But clicking a second time on
b2 prints the expected result a second time. Continuing to click on
b2 just increases the list of printed results. This uselessly clutters the notebook I want to distribute.
I want a
Button to execute a function and simply display its results as near as possible to what pressing
Shift + Return in an input cell would do.
I further want it to overwrite previous output.
Ideally I would place the
Button expression in a hidden initialization cell so only the actual button appears in the deployed notebook.
Does anyway exist to get a Button to do what I've described? How?