@datagrok/charpy v1.0.5
ChaRPy
ChaRPy is a package for the Datagrok platform. It extends Datagrok viewers with two commands, "To Python script" and "To R script", which translate a selected viewer to Python or R code, respectively, along with executing this code for displaying the resulting plot. The two commands are available via a hamburger menu (a top-left button in a viewer's header), and supported for most of the viewers in Datagrok.
The selected command forms a script in R or Python which in turn generates a plot identical or very close to the plot of the selected viewer. The script responsible for the plot becomes available along with the resulting plot itself, displayed via a Scripting Viewer.
ChaRPy uses ggplot2 for R, and plotly for Python.
In addition to scripting viewers, the package also showcases the following Datagrok's facilities:
- Creating and showing a modal dialog,
let d = ui.dialog("Title"); ...; d.showModal(true);
- Placing viewers in a modal dialog using splitters,
ui.splitV
andui.splitH
- Creating a new viewer by viewer type by
DG.Viewer.fromType
, in this case — a regular viewer of a corresponding type, and a scripting viewer - Expanding Datagrok's context menu with new items (
grok.events.onContextMenu.subscribe
,args.args.menu.item
)
Here are the files of particular interest:
- src/package.js: a function that defines and registers script generation logic, driven by templates stored in the below two files.
- src/mapPy.json, src/mapR.json: templates used in forming Python and R scripts based on selected viewer's type.
See also: