Use file input
When you use the file
annotation for the input parameter,
Datagrok creates an interface to load the file.
- Result
- Python
- JavaScript
#name: DfFromJSON
#description: Loads a dataframe from JSON file
#language: python
#tags: template, demo, FileIo
#input: file json_file {caption:JSON file} [A JSON file to load a dataframe]
#output: dataframe df
df = pd.read_json(json_file)
//name: DfFromJSON
//description: Loads a file and returns first sheet name
//language: javascript
//tags: template, demo, FileIo
//input: file uploadedFile {caption:Excel file}
//output: string first_sheet_name
const importWb = new ExcelJS.Workbook();
await importWb.xlsx.load(uploadedFile.data);
first_sheet_name = importWb.worksheets[0].name;
You can upload the file from your computer, choose it from Datagrok file storage, or use any of the file connectors supported by Datagrok.
File I/O connectors
The blob
input works in a very similar way but provides the binary stream instead of a file name.
#name: BlobTest
#description: Example of Blob usage
#language: python
#tags: template, demo
#input: blob array_blob
#output: string typeofblob
typeofblob = type(array_blob)
You can use this capability to effectively transfer a large set of data from one Datagrok function/script to another.