|
1 | | -# Getting-started-with-Syncfusion-Grid-component-in-Streamlit-app |
2 | | -This repository contains the Syncfusion Grid component example using Streamlit application. |
| 1 | +# Getting Started with the Syncfusion Grid component in the Streamlit Application |
| 2 | + |
| 3 | +This article provides a step-by-step guide for setting up a [Streamlit](https://streamlit.io/) application with a Python environment and integrating the Syncfusion Grid components. |
| 4 | + |
| 5 | +`Streamlit` is a free and open-source framework that enables quick development and sharing of visually appealing web applications for machine learning and data science. |
| 6 | + |
| 7 | +## Setting up the Streamlit application |
| 8 | + |
| 9 | +To begin working with the Streamlit framework, it is recommended to create a Python environment using [venv](https://docs.python.org/3/library/venv.html). Refer to the below command to create a new Python environment: |
| 10 | + |
| 11 | +```bash |
| 12 | +python -m venv my-app |
| 13 | +``` |
| 14 | + |
| 15 | +Upon completing the aforementioned step to create **my-app**, run the following command to install Streamlit: |
| 16 | + |
| 17 | +```bash |
| 18 | +cd my-app |
| 19 | +pip install streamlit |
| 20 | +``` |
| 21 | + |
| 22 | +Now that **my-app** is ready to run with default settings, let's add Syncfusion Grid component to the application. |
| 23 | + |
| 24 | +## Add the Syncfusion Grid package |
| 25 | + |
| 26 | +Install the Syncfusion Grid component package from [PyPI](https://pypi.org/project/ej2-streamlit-grids/) by executing the following command: |
| 27 | + |
| 28 | +```sh |
| 29 | +pip install ej2-streamlit-grids |
| 30 | +``` |
| 31 | + |
| 32 | +## Add the Syncfusion Grid component |
| 33 | + |
| 34 | +Follow the below steps to add the Syncfusion Grid component to the Streamlit application: |
| 35 | + |
| 36 | +1\. Create a Python file named **demo.py** and import the Grid component into the file: |
| 37 | + |
| 38 | +```py |
| 39 | +from ej2_streamlit_grids import GridComponent, GridProps |
| 40 | +``` |
| 41 | + |
| 42 | +2\. Create a `CSV` file named **dataset.csv** and populate it with data in the following format: |
| 43 | + |
| 44 | +```sh |
| 45 | +OrderID, CustomerName, OrderDate, Freight, ShippedDate, ShipCountry |
| 46 | +10248, Paul Henriot, 7/4/1996, 3ドル2.38, 7/16/1996, France |
| 47 | +10249, Karin Josephs, 7/5/1996, 1ドル1.61, 7/10/1996, Germany |
| 48 | +10250, Mario Pontes, 7/8/1996, 6ドル5.83, 7/12/1996, Brazil |
| 49 | +10251, Mary Saveley, 7/8/1996, 4ドル1.34, 7/15/1996, France |
| 50 | +``` |
| 51 | + |
| 52 | +3\. Read the data from the `CSV` file and initialize the `GridProps` object: |
| 53 | + |
| 54 | +```py |
| 55 | +data = pd.read_csv('dataset.csv') |
| 56 | +props = GridProps(data) |
| 57 | + |
| 58 | +GridComponent(props) |
| 59 | +``` |
| 60 | + |
| 61 | +## Import Syncfusion CSS styles |
| 62 | + |
| 63 | +You can import themes for the Syncfusion Streamlit component from the CDN. Refer to the [themes topic](https://ej2.syncfusion.com/react/documentation/appearance/theme/) to learn more about built-in themes. The `Material` theme is the default theme for the Streamlit Grid component. |
| 64 | + |
| 65 | +You can change the default theme with any of the available [built-in themes](https://ej2.syncfusion.com/react/documentation/appearance/theme/). In this article, the `Fluent` theme is applied using `theme` property, which are available in CDN. The necessary `Fluent` CSS styles for the Grid component were passed into the `theme` property, which is referenced using the code snippet below. |
| 66 | + |
| 67 | +```py |
| 68 | +props.theme = 'https://cdn.syncfusion.com/ej2/22.1.34/fluent.css' |
| 69 | +``` |
| 70 | + |
| 71 | +## Run the application |
| 72 | + |
| 73 | +Here is the summarized code for the above steps in the **demo.py** file: |
| 74 | + |
| 75 | +```py |
| 76 | +from ej2_streamlit_grids import GridComponent, GridProps |
| 77 | +import pandas as pd |
| 78 | + |
| 79 | +data = pd.read_csv('dataset.csv') |
| 80 | +props = GridProps(data) |
| 81 | +props.theme = 'https://cdn.syncfusion.com/ej2/22.1.34/fluent.css' |
| 82 | + |
| 83 | +GridComponent(props) |
| 84 | +``` |
| 85 | + |
| 86 | +Ensure that terminal is in the correct project directory where **demo.py** is located. Run the application using the following command: |
| 87 | + |
| 88 | +```sh |
| 89 | +streamlit run demo.py |
| 90 | +``` |
| 91 | + |
| 92 | +The output will appear as follows: |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +## Grid features demo |
| 97 | + |
| 98 | +The Grid component is rendered along with some additional features in the **demo.py** file located in the **demos** folder. The resulting output with these features will be displayed as depicted below: |
| 99 | + |
| 100 | + |
0 commit comments