def test_st_help(self): """Test st.help.""" st.help(st.header) el = self.get_delta_from_queue().new_element self.assertEqual(el.doc_string.name, "header") self.assertEqual(el.doc_string.module, "streamlit") self.assertTrue( el.doc_string.doc_string.startswith( "Display text in header formatting.")) self.assertEqual(el.doc_string.type, "<class 'method'>") self.assertEqual(el.doc_string.signature, "(body)")
def test_st_write(self): """Test st.write function (since it's from __init__).""" st.help(st.write) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, 'write') self.assertEqual(ds.module, 'streamlit') if is_python_2: self.assertEqual(ds.type, '<type \'function\'>') else: self.assertEqual(ds.type, '<class \'function\'>') self.assertEqual(ds.signature, '(*args)') self.assertTrue(ds.doc_string.startswith('Write arguments to the'))
def test_st_write(self): """Test st.write function (since it's from __init__).""" st.help(st.write) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "write") self.assertEqual(ds.module, "streamlit") if is_python_2: self.assertEqual(ds.type, "<type 'function'>") else: self.assertEqual(ds.type, "<class 'function'>") self.assertEqual(ds.signature, "(*args)") self.assertTrue(ds.doc_string.startswith("Write arguments to the"))
def test_basic_func_without_doc(self): """Test basic function without docstring.""" def my_func(some_param, another_param=123): pass st.help(my_func) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual("my_func", ds.name) self.assertEqual("help_test", ds.module) self.assertEqual("<class 'function'>", ds.type) self.assertEqual("(some_param, another_param=123)", ds.signature) self.assertEqual("No docs available.", ds.doc_string)
def test_unwrapped_deltagenerator_func(self): """Test unwrapped Streamlit DeltaGenerator function.""" st.help(st.dataframe) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "dataframe") self.assertEqual(ds.module, "streamlit") if is_python_2: self.assertEqual(ds.type, "<type 'function'>") else: self.assertEqual(ds.type, "<class 'function'>") self.assertEqual(ds.signature, "(data=None, width=None, height=None)") self.assertTrue(ds.doc_string.startswith("Display a dataframe"))
def test_doc_defined_for_type(self): """When the docs are defined for the type on an object, but not the object, we expect the docs of the type. This is the case of ndarray generated as follow. """ array = np.arange(1) st.help(array) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "") self.assertTrue("ndarray" in ds.doc_string)
def test_doc_type_is_type(self): """When the type of the object is type and no docs are defined, we expect docs are not available""" class MyClass(object): pass st.help(MyClass) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(type(MyClass), type) self.assertEqual(ds.name, "MyClass") self.assertEqual(ds.module, "help_test") self.assertEqual(ds.doc_string, "No docs available.")
def test_st_cache(self): """Test st.cache function (since it's from the 'caching' module).""" st.help(st.cache) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, 'cache') self.assertEqual(ds.module, 'streamlit') if is_python_2: self.assertEqual(ds.type, '<type \'function\'>') else: self.assertEqual(ds.type, '<class \'function\'>') self.assertEqual(ds.signature, '(func=None, on_disk=False)') self.assertTrue(ds.doc_string.startswith('Function decorator to'))
def test_builtin_obj(self): """Test a built-in function.""" st.help(123) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "") self.assertEqual(ds.module, "") if is_python_2: self.assertEqual(ds.type, "<type 'int'>") else: self.assertEqual(ds.type, "<class 'int'>") self.assertEqual(ds.signature, "") self.assertTrue(len(ds.doc_string) > 0)
def test_unwrapped_deltagenerator_func(self): """Test unwrapped Streamlit DeltaGenerator function.""" st.help(st.dataframe) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, 'dataframe') self.assertEqual(ds.module, 'streamlit') if is_python_2: self.assertEqual(ds.type, '<type \'function\'>') else: self.assertEqual(ds.type, '<class \'function\'>') self.assertEqual(ds.signature, '(data=None)') self.assertTrue(ds.doc_string.startswith('Display a dataframe'))
def test_builtin_func(self): """Test a built-in function.""" st.help(dir) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "dir") if is_python_2: self.assertEqual(ds.module, "__builtin__") self.assertEqual(ds.type, "<type 'builtin_function_or_method'>") else: self.assertEqual(ds.module, "builtins") self.assertEqual(ds.type, "<class 'builtin_function_or_method'>") self.assertEqual(ds.signature, "") self.assertTrue(len(ds.doc_string) > 0)
def test_builtin_func(self): """Test a built-in function.""" st.help(dir) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, 'dir') if is_python_2: self.assertEqual(ds.module, '__builtin__') self.assertEqual(ds.type, '<type \'builtin_function_or_method\'>') else: self.assertEqual(ds.module, 'builtins') self.assertEqual(ds.type, '<class \'builtin_function_or_method\'>') self.assertEqual(ds.signature, '') self.assertTrue(len(ds.doc_string) > 0)
def show_utilities() -> None: st.header("Utility functions") st.subheader("Show help for an object") with st.echo(): if st.button("Show help"): st.help(pd.DataFrame) st.markdown('-' * 6) st.subheader("Placeholder") with st.echo(): placeholder = st.empty() st.info("This message was created **after** the placeholder!") choice = st.radio("Option", [None, 'markdown', 'dataframe']) if choice == "markdown": placeholder.markdown("This was written at a later point in time :wave:") elif choice == "dataframe": placeholder.dataframe(pd.DataFrame(np.random.randint(0, 100, size=(5, 4)), columns=list('ABCD'))) st.markdown('-' * 6) st.subheader("Get and set options") st.write("""Show and change options for streamlit. Available options can be viewed by entering `streamlit config show` in the terminal. Option key has structure `section.optionName`. """) st.code(""" ... [server] ... # Max size, in megabytes, for files uploaded with the file_uploader. # Default: 200 maxUploadSize = 200 ... """) with st.echo(): up_size = st.get_option("server.maxUploadSize") st.write(f"Maximum upload size upload size is `{up_size} MB`") st.write(""" #### Updating client settings Changing config options currently works ony for client options, i.e.: * client.caching * client.displayEnabled """)
def test_st_help(self): """Test st.help.""" st.help(st.header) el = self.get_delta_from_queue().new_element self.assertEqual(el.doc_string.name, "header") self.assertEqual(el.doc_string.module, "streamlit") self.assertTrue( el.doc_string.doc_string.startswith( "Display text in header formatting.")) if sys.version_info >= (3, 0): self.assertEqual(el.doc_string.type, "<class 'function'>") else: self.assertEqual(el.doc_string.type, u"<type 'function'>") self.assertEqual(el.doc_string.signature, "(body)")
def test_deltagenerator_func(self): """Test Streamlit DeltaGenerator function.""" st.help(st.audio) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, 'audio') self.assertEqual(ds.module, 'streamlit') if is_python_2: self.assertEqual(ds.type, '<type \'function\'>') self.assertEqual(ds.signature, '(data, format=u\'audio/wav\')') else: self.assertEqual(ds.type, '<class \'function\'>') self.assertEqual(ds.signature, '(data, format=\'audio/wav\')') self.assertTrue(ds.doc_string.startswith('Display an audio player'))
def test_deltagenerator_func(self): """Test Streamlit DeltaGenerator function.""" st.help(st.audio) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "audio") self.assertEqual(ds.module, "streamlit") if is_python_2: self.assertEqual(ds.type, "<type 'function'>") self.assertEqual(ds.signature, "(data, format=u'audio/wav')") else: self.assertEqual(ds.type, "<class 'function'>") self.assertEqual(ds.signature, "(data, format='audio/wav')") self.assertTrue(ds.doc_string.startswith("Display an audio player"))
def test_basic_func_without_doc(self): """Test basic function without docstring.""" def my_func(some_param, another_param=123): pass st.help(my_func) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, 'my_func') self.assertEqual(ds.module, 'help_test') if is_python_2: self.assertEqual(ds.type, '<type \'function\'>') else: self.assertEqual(ds.type, '<class \'function\'>') self.assertEqual(ds.signature, '(some_param, another_param=123)') self.assertEqual(ds.doc_string, 'No docs available.')
def test_basic_func_without_doc(self): """Test basic function without docstring.""" def my_func(some_param, another_param=123): pass st.help(my_func) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "my_func") self.assertEqual(ds.module, "help_test") if is_python_2: self.assertEqual(ds.type, "<type 'function'>") else: self.assertEqual(ds.type, "<class 'function'>") self.assertEqual(ds.signature, "(some_param, another_param=123)") self.assertEqual(ds.doc_string, "No docs available.")
def test_st_cache(self): """Test st.cache function (since it's from the 'caching' module).""" st.help(st.cache) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual(ds.name, "cache") self.assertEqual(ds.module, "streamlit") if is_python_2: self.assertEqual(ds.type, "<type 'function'>") else: self.assertEqual(ds.type, "<class 'function'>") self.assertEqual( ds.signature, ("(func=None, persist=False, " "ignore_hash=False, show_spinner=True)"), ) self.assertTrue(ds.doc_string.startswith("Function decorator to"))
def test_basic_func_with_doc(self): """Test basic function with docstring.""" def my_func(some_param, another_param=123): """This is the doc""" pass st.help(my_func) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual("my_func", ds.name) self.assertEqual("help_test", ds.module) if is_python_2: self.assertEqual("<type 'function'>", ds.type) else: self.assertEqual("<class 'function'>", ds.type) self.assertEqual("(some_param, another_param=123)", ds.signature) self.assertEqual("This is the doc", ds.doc_string)
def options_view(tickers: Ticker, symbols: List[str]): """Provides an illustration of the `option_chain` method Arguments: tickers {Ticker} -- A yahaooquery Ticker object symbols {List[str]} -- A list of symbols """ st.header("Option Chain") st.write(""" Yahooquery also gives you the ability to view [option chain]\ (https://www.investopedia.com/terms/o/optionchain.asp) data for all expiration dates for a given symbol(s) """) st.help(getattr(Ticker, "option_chain")) st.code(f"Ticker({symbols}).option_chain", language="python") data = get_data(tickers, "option_chain") st.dataframe(data)
def test_deltagenerator_func(self): """Test Streamlit DeltaGenerator function.""" st.help(st.audio) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual("audio", ds.name) self.assertEqual("streamlit", ds.module) if is_python_2: self.assertEqual("<type 'instancemethod'>", ds.type) self.assertEqual("(data, format=u'audio/wav', start_time=0)", ds.signature) else: self.assertEqual("<class 'method'>", ds.type) self.assertEqual("(data, format='audio/wav', start_time=0)", ds.signature) self.assertTrue(ds.doc_string.startswith("Display an audio player"))
def test_deltagenerator_func(self): """Test Streamlit DeltaGenerator function.""" st.help(st.audio) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual("audio", ds.name) self.assertEqual("streamlit", ds.module) self.assertEqual("<class 'method'>", ds.type) self.assertEqual( "(data: Union[str, bytes, _io.BytesIO, io.RawIOBase, " "_io.BufferedReader, ForwardRef('npt.NDArray[Any]'), NoneType], " "format: str = 'audio/wav', start_time: int = 0) -> " "'DeltaGenerator'", ds.signature, ) self.assertTrue(ds.doc_string.startswith("Display an audio player"))
def test_st_cache(self): """Test st.cache function (since it's from the 'caching' module).""" st.help(st.cache) ds = self.get_delta_from_queue().new_element.doc_string self.assertEqual("cache", ds.name) self.assertEqual("streamlit", ds.module) if is_python_2: self.assertEqual("<type 'function'>", ds.type) else: self.assertEqual("<class 'function'>", ds.type) self.assertEqual( ds.signature, ("(func=None, persist=False, " "allow_output_mutation=False, show_spinner=True, suppress_st_warning=False, hash_funcs=None, ignore_hash=False)" ), ) self.assertTrue(ds.doc_string.startswith("Function decorator to"))
def base_multiple_view(tickers: Ticker, symbols: List[str]): """A view for multiple Ticker requests The user can select all or multiple endpoints and the help text, code and result will be presented. Arguments: tickers {Ticker} -- A yahaooquery Ticker object symbols {List[str]} -- A list of symbols """ st.header("Base Endpoints - Multiple") st.markdown( """ Two methods to the `Ticker` class allow you to obtain multiple endpoints with one call. - the `get_endpoints` method takes a list of allowable endpoints, which you can view through `Ticker._ENDPOINTS` - the `all_endpoints` property retrieves all Base endpoints""" ) method = st.selectbox("Select Method", options=["All Endpoints", "Multiple Endpoints"], index=1) if method == "All Endpoints": st.help(getattr(Ticker, "all_endpoints")) st.code(f"Ticker({symbols}).all_endpoints", language="python") data = get_data(tickers, "all_endpoints") st.json(data) else: default_endpoints = ["assetProfile"] endpoints = st.multiselect( "Select endpoints", options=sorted(Ticker._ENDPOINTS), # pylint: disable=protected-access default=default_endpoints, ) st.help(getattr(Ticker, "get_endpoints")) st.code(f"Ticker({symbols}).get_endpoints({endpoints})", language="python") if not endpoints: st.warning("You must select at least one endpoint") else: data = get_data(tickers, "get_endpoints")(endpoints) st.json(data)
def homepage_view(tickers: Ticker, symbols: List[str]): """Provides the view of the Home Page Arguments: tickers {Ticker} -- A yahaooquery Ticker object symbols {List[str]} -- A list of symbols """ st.markdown( f""" This app demonstrates the use of the [YahooQuery]\ (https://github.com/dpguthrie/yahooquery) package ### Instructions Enter a symbol or list of symbols in the box to the left (**comma separated**). Then select different pages in the dropdown to view the data available to you. ### Installation ```python pip install yahooquery ``` ### Ticker Usage The `Ticker` class provides the access point to data residing on Yahoo Finance. It accepts either a symbol or list of symbols. Additionally, you can supply `formatted` as a keyword argument to the class to format the data returned from the API (default is `True`) ```python from yahooquery import Ticker tickers = Ticker({symbols}) ``` """ ) st.help(tickers)
def draw_all(key): st.write(""" # Hello Hi **there!** This is `code`. ``` This is block code. ``` """) radio_markdown = """ h2. Select a number --- You have **3** choices! """ st.checkbox("Cool?", key=key, help='Press to confirm checkbox') st.radio("Pick a number", [1, 2, 3], key=key, help=radio_markdown) st.button("Click me!", key=key) st.slider("Pick a number", key=key) st.select_slider("Pick a number", [1, 2, 3], key=key) st.number_input("Pick a number", key=key) st.text_input("Pick a number", key=key) st.text_area("Pick a number", key=key) st.selectbox("Pick a number", [1, 2, 3], key=key) st.multiselect("Pick a number", [1, 2, 3], key=key) st.file_uploader("Pick a file", key=key) st.color_picker("Favorite color", key=key) with st.beta_expander("Expand me!"): st.write("hi") st.progress(0.6) st.json({"data": [1, 2, 3, 4]}) st.dataframe({"data": [1, 2, 3, 4]}) st.table({"data": [1, 2, 3, 4]}) st.line_chart({"data": [1, 2, 3, 4]}) st.help(st.write)
def test_st_help(self): """Test st.help.""" st.help(st.header) el = self.get_delta_from_queue().new_element self.assertEqual(el.doc_string.name, "header") self.assertEqual(el.doc_string.module, "streamlit") self.assertTrue( el.doc_string.doc_string.startswith("Display text in header formatting.") ) self.assertEqual(el.doc_string.type, "<class 'method'>") if sys.version_info[1] == 7: # Python 3.7 represents the signature slightly differently self.assertEqual( el.doc_string.signature, "(body: str, anchor: Union[str, NoneType] = None) -> 'DeltaGenerator'", ) else: self.assertEqual( el.doc_string.signature, "(body: str, anchor: Optional[str] = None) -> 'DeltaGenerator'", )
def test_st_help(self): """Test st.help.""" dg = st.help(st.header) el = self.get_delta_from_queue().new_element self.assertEqual(el.doc_string.name, 'header') self.assertEqual(el.doc_string.module, 'streamlit') self.assertTrue( el.doc_string.doc_string.startswith('Display text in header formatting.')) if sys.version_info >= (3, 0): self.assertEqual(el.doc_string.type, '<class \'function\'>') else: self.assertEqual(el.doc_string.type, u'<type \'function\'>') self.assertEqual(el.doc_string.signature, '(body)')
def show_components() -> None: st.header("Demonstrate use of a custom component") st.markdown( "A component is just a collection of streamlit widgets and custom functions." "To use a custom components simply import it and call the required function" ) st.write("This project has the following folder structure:") st.text(""" . ├── app.py ├── data │ ├── external │ └── raw │ ├── data_1.csv ... │ └── web_1.json ... ├── ui │ ├── basics.py │ ├── components │ │ └── data_selector.py │ ├── extras.py │ ├── interactive.py ... """) with st.echo(): import ui.components.data_selector as file_selector file_selector.select_file("raw", st, [".csv", ".json"]) st.markdown('-' * 6) st.write("Help for the custom component is available via `st.help`") with st.echo(): st.help(file_selector.select_file)