# Apps and workflows Recipes for using handcalcs beyond a notebook: scripts, reusable calculation functions, parametric studies and web or desktop apps. ## Render from a plain Python script *Asked in {issue}`203`.* `HandCalcs` works anywhere Python runs. Give it the source and the namespace to take values from: ```python from handcalcs import HandCalcs from handcalcs.renderers import ASCIIRenderer source = """ w = 5 L = 6 M = w * L**2 / 8 """ namespace = {} exec(source, namespace) print(HandCalcs(ASCIIRenderer())(source, namespace)) ``` Pass a `pathlib.Path` instead of a string and handcalcs runs the file for you: `HandCalcs(renderer)(Path("beam.py"))`. ## Turn a calculation function into a rendered one *Asked in {issue}`107` and {issue}`173`.* `@handcalc` makes a function return its result and its rendered calculation: ```python from handcalcs import handcalc from handcalcs.renderers import MarkdownRenderer @handcalc(MarkdownRenderer()) def moment(w, L): M = w * L**2 / 8 return M value, markdown = moment(5, 6) ``` A function you already have, in a module you don't want to change, can be wrapped when you call it: `value, markdown = handcalc(MarkdownRenderer())(beams.moment)(5, 6)`. See [Functions: `@handcalc`](../interfaces/decorator.md). ## Run one calculation for many designs Write the calculation once as a script with sample values. Then render it for each row of a table of inputs. Every line computed from an input is recomputed: ```python import csv import pathlib from handcalcs import HandCalcs, find_inputs from handcalcs.renderers import LatexRenderer calc = pathlib.Path("beam.py") print(find_inputs(calc)) # {'w': 5, 'L': 6}: the names you can set hc = HandCalcs(LatexRenderer()) with open("beams.csv") as f: # columns: mark, w, L for row in csv.DictReader(f): case = {"w": float(row["w"]), "L": float(row["L"])} pathlib.Path(f"out/{row['mark']}.tex").write_text(hc(calc, inputs=case)) ``` Units in the script are kept: with `L = 6 * m` in the script, `inputs={"L": 8}` renders `L = 8 * m`. In a notebook, `%%render inputs=case` does the same for a cell. See [Rendering many input sets](../interfaces/object-oriented.md#rendering-many-input-sets). ## Rendered calculations in a web app *Asked in {issue}`167`.* The HTML renderer returns a self-contained fragment (its own `