1
1
import os
2
2
import streamlit .components .v1 as components
3
+ import spec
3
4
4
5
# Create a _RELEASE constant. We'll set this to False while we're developing
5
6
# the component, and True when we're ready to package and distribute it.
@@ -66,6 +67,8 @@ def g2(options, style=None, key=None):
66
67
#
67
68
# "default" is a special argument that specifies the initial return
68
69
# value of the component before the user has interacted with it.
70
+ # Loop to change pd.DataFrame to JSON Object.
71
+ spec .normalize_options (options )
69
72
component_value = _component_func (options = options , style = style , key = key )
70
73
return component_value
71
74
@@ -80,22 +83,45 @@ def st_g2(options, style=None, key=None):
80
83
# `$ streamlit run streamlit_g2/__init__.py`
81
84
if not _RELEASE :
82
85
import streamlit as st
86
+ import pandas as pd
87
+
88
+ df = pd .DataFrame (
89
+ [["Sports" , 275 ], ["Strategy" , 115 ], ["Action" , 120 ], ["Shooter" , 350 ], ["Other" , 150 ]],
90
+ columns = ["genre" , "sold" ],
91
+ )
83
92
84
93
options = {
85
94
"autoFit" : True ,
86
- "type" : "interval" ,
87
- "data" : [
88
- { "genre" : "Sports" , "sold" : 275 },
89
- { "genre" : "Strategy" , "sold" : 115 },
90
- { "genre" : "Action" , "sold" : 120 },
91
- { "genre" : "Shooter" , "sold" : 350 },
92
- { "genre" : "Other" , "sold" : 150 },
93
- ],
94
- "encode" : {
95
- "x" : "genre" ,
96
- "y" : "sold" ,
97
- "color" : "genre" ,
98
- }
95
+ "type" : "spaceFlex" ,
96
+ "children" : [
97
+ {
98
+ "type" : "interval" ,
99
+ "data" : [
100
+ { "genre" : "Sports" , "sold" : 275 },
101
+ { "genre" : "Strategy" , "sold" : 115 },
102
+ { "genre" : "Action" , "sold" : 120 },
103
+ { "genre" : "Shooter" , "sold" : 350 },
104
+ { "genre" : "Other" , "sold" : 150 },
105
+ ],
106
+ "encode" : {
107
+ "x" : "genre" ,
108
+ "y" : "sold" ,
109
+ "color" : "genre" ,
110
+ },
111
+ },
112
+ {
113
+ "type" : "line" ,
114
+ "data" : df ,
115
+ "encode" : {
116
+ "x" : "genre" ,
117
+ "y" : "sold" ,
118
+ "shape" : "smooth"
119
+ },
120
+ "style" : {
121
+ "lineWidth" : 2 ,
122
+ }
123
+ }
124
+ ]
99
125
}
100
126
101
127
g2 (options = options , style = { "height" : "400px" }, key = "streamlit-g2" )
0 commit comments