Run a project with Streamlit¶
main()
¶
usage: onecode-start [-h] [--modules [MODULES [MODULES ...]]]
Start the OneCode Project in Streamlit mode.
optional arguments:
-h, --help show this help message and exit
--modules [MODULES [MODULES ...]]
Optional list of modules to import first
prepare_streamlit_file(project_path, to_file)
¶
Prepare the Streamlit App Python file from the given OneCode project and dump it to the specified file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_path |
str
|
Path to the root of the OneCode project. |
required |
to_file |
str
|
Path of the output file to dump the Streamlit Python code to. |
required |
process(calls)
¶
Evaluate the given calls such as:
- result of evaluation is interpreted as a code block.
- resulting code block is appended to the list of their corresponding element type
(i-e input code block list for InputElement
and output code block list for
OutputElement
).
Ensure the proper Project().mode
is set before calling this function (as it will control
the evaluation of the code call). This function is typically used for Streamlit code generation.
Although the prepare_streamlit_file()
function directly pipes the calls from the code
call graph (through process_call_graph()
), you may input your own code calls (see example
below).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
calls |
List[Dict[str, str]]
|
List of |
required |
Returns:
Type | Description |
---|---|
List[str]
|
The pair of two lists: one containing the code evaluation for the |
List[str]
|
containing the code evaluation for the |
Example
Project().mode = Mode.STREAMLIT
# processing a single call of Slider element
process([{"func": "onecode.slider", "loc": "onecode.slider('My Slider', 0.4)"}])
# => returns the streamlit code for this parameter, i-e:
# Slider {self.key}
# my_slider = st.slider(
# 'My Slider',
# min_value=0.,
# max_value=1.,
# value=0.4,
# step=0.1,
# disabled=False,
# key='my_slider'
# )
# piping the entire call graph of a OneCode Project
statements = process_call_graph(project_path)
for v in statements.values():
inputs, outputs = process(v["calls"])
# ...