File size: 143,862 Bytes
52982d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
{"id": "e4409cd96e13-0", "text": "search\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\nmenu\nHome/\nStreamlit library/\nGet started/\nMain concepts\nMain concepts\n\nWorking with Streamlit is simple. First you sprinkle a few Streamlit commands into a normal Python script, then you run it with streamlit run:\n\nstreamlit run your_script.py [-- script args]\nCopy\n\nAs soon as you run the script as shown above, a local Streamlit server will spin up and your app will open in a new tab in your default web browser. The app is your canvas, where you'll draw charts, text, widgets, tables, and more.\n\nWhat gets drawn in the app is up to you. For example st.text writes raw text to your app, and st.line_chart draws \u2014 you guessed it \u2014 a line chart. Refer to our API documentation to see all commands that are available to you.\n\npush_pin\nNote\n\nWhen passing your script some custom arguments, they must be passed after two dashes. Otherwise the arguments get interpreted as arguments to Streamlit itself.\n\nAnother way of running Streamlit is to run it as a Python module. This can be useful when configuring an IDE like PyCharm to work with Streamlit:\n\n# Running\npython -m streamlit run your_script.py\n\n# is equivalent to:\nstreamlit run your_script.py\nCopy\nstar\nTip\n\nYou can also pass a URL to streamlit run! This is great when combined with GitHub Gists. For example:\n\nstreamlit run https://raw.githubusercontent.com/streamlit/demo-uber-nyc-pickups/master/streamlit_app.py\nCopy\nDevelopment flow", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-1", "text": "Every time you want to update your app, save the source file. When you do that, Streamlit detects if there is a change and asks you whether you want to rerun your app. Choose \"Always rerun\" at the top-right of your screen to automatically update your app every time you change its source code.\n\nThis allows you to work in a fast interactive loop: you type some code, save it, try it out live, then type some more code, save it, try it out, and so on until you're happy with the results. This tight loop between coding and viewing results live is one of the ways Streamlit makes your life easier.\n\nstar\nTip\n\nWhile developing a Streamlit app, it's recommended to lay out your editor and browser windows side by side, so the code and the app can be seen at the same time. Give it a try!\n\nAs of Streamlit version 1.10.0 and higher, Streamlit apps cannot be run from the root directory of Linux distributions. If you try to run a Streamlit app from the root directory, Streamlit will throw a FileNotFoundError: [Errno 2] No such file or directory error. For more information, see GitHub issue #5239.\n\nIf you are using Streamlit version 1.10.0 or higher, your main script should live in a directory other than the root directory. When using Docker, you can use the WORKDIR command to specify the directory where your main script lives. For an example of how to do this, read Create a Dockerfile.\n\nData flow\n\nStreamlit's architecture allows you to write apps the same way you write plain Python scripts. To unlock this, Streamlit apps have a unique data flow: any time something must be updated on the screen, Streamlit reruns your entire Python script from top to bottom.\n\nThis can happen in two situations:\n\nWhenever you modify your app's source code.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-2", "text": "This can happen in two situations:\n\nWhenever you modify your app's source code.\n\nWhenever a user interacts with widgets in the app. For example, when dragging a slider, entering text in an input box, or clicking a button.\n\nWhenever a callback is passed to a widget via the on_change (or on_click) parameter, the callback will always run before the rest of your script. For details on the Callbacks API, please refer to our Session State API Reference Guide.\n\nAnd to make all of this fast and seamless, Streamlit does some heavy lifting for you behind the scenes. A big player in this story is the @st.cache_data decorator, which allows developers to skip certain costly computations when their apps rerun. We'll cover caching later in this page.\n\nDisplay and style data\n\nThere are a few ways to display data (tables, arrays, data frames) in Streamlit apps. Below, you will be introduced to magic and st.write(), which can be used to write anything from text to tables. After that, let's take a look at methods designed specifically for visualizing data.\n\nUse magic\n\nYou can also write to your app without calling any Streamlit methods. Streamlit supports \"magic commands,\" which means you don't have to use st.write() at all! To see this in action try this snippet:\n\n\"\"\"\n# My first app\nHere's our first attempt at using data to create a table:\n\"\"\"\n\nimport streamlit as st\nimport pandas as pd\ndf = pd.DataFrame({\n 'first column': [1, 2, 3, 4],\n 'second column': [10, 20, 30, 40]\n})\n\ndf\nCopy\n\nAny time that Streamlit sees a variable or a literal value on its own line, it automatically writes that to your app using st.write(). For more information, refer to the documentation on magic commands.\n\nWrite a data frame", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-3", "text": "Write a data frame\n\nAlong with magic commands, st.write() is Streamlit's \"Swiss Army knife\". You can pass almost anything to st.write(): text, data, Matplotlib figures, Altair charts, and more. Don't worry, Streamlit will figure it out and render things the right way.\n\nimport streamlit as st\nimport pandas as pd\n\nst.write(\"Here's our first attempt at using data to create a table:\")\nst.write(pd.DataFrame({\n 'first column': [1, 2, 3, 4],\n 'second column': [10, 20, 30, 40]\n}))\nCopy\n\nThere are other data specific functions like st.dataframe() and st.table() that you can also use for displaying data. Let's understand when to use these features and how to add colors and styling to your data frames.\n\nYou might be asking yourself, \"why wouldn't I always use st.write()?\" There are a few reasons:\n\nMagic and st.write() inspect the type of data that you've passed in, and then decide how to best render it in the app. Sometimes you want to draw it another way. For example, instead of drawing a dataframe as an interactive table, you may want to draw it as a static table by using st.table(df).\nThe second reason is that other methods return an object that can be used and modified, either by adding data to it or replacing it.\nFinally, if you use a more specific Streamlit method you can pass additional arguments to customize its behavior.\n\nFor example, let's create a data frame and change its formatting with a Pandas Styler object. In this example, you'll use Numpy to generate a random sample, and the st.dataframe() method to draw an interactive table.\n\npush_pin\nNote", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-4", "text": "push_pin\nNote\n\nThis example uses Numpy to generate a random sample, but you can use Pandas DataFrames, Numpy arrays, or plain Python arrays.\n\nimport streamlit as st\nimport numpy as np\n\ndataframe = np.random.randn(10, 20)\nst.dataframe(dataframe)\nCopy\n\nLet's expand on the first example using the Pandas Styler object to highlight some elements in the interactive table.\n\nimport streamlit as st\nimport numpy as np\nimport pandas as pd\n\ndataframe = pd.DataFrame(\n np.random.randn(10, 20),\n columns=('col %d' % i for i in range(20)))\n\nst.dataframe(dataframe.style.highlight_max(axis=0))\nCopy\n\nStreamlit also has a method for static table generation: st.table().\n\nimport streamlit as st\nimport numpy as np\nimport pandas as pd\n\ndataframe = pd.DataFrame(\n np.random.randn(10, 20),\n columns=('col %d' % i for i in range(20)))\nst.table(dataframe)\nCopy\nDraw charts and maps\n\nStreamlit supports several popular data charting libraries like Matplotlib, Altair, deck.gl, and more. In this section, you'll add a bar chart, line chart, and a map to your app.\n\nDraw a line chart\n\nYou can easily add a line chart to your app with st.line_chart(). We'll generate a random sample using Numpy and then chart it.\n\nimport streamlit as st\nimport numpy as np\nimport pandas as pd\n\nchart_data = pd.DataFrame(\n np.random.randn(20, 3),\n columns=['a', 'b', 'c'])\n\nst.line_chart(chart_data)\nCopy\nPlot a map\n\nWith st.map() you can display data points on a map. Let's use Numpy to generate some sample data and plot it on a map of San Francisco.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-5", "text": "import streamlit as st\nimport numpy as np\nimport pandas as pd\n\nmap_data = pd.DataFrame(\n np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],\n columns=['lat', 'lon'])\n\nst.map(map_data)\nCopy\nWidgets\n\nWhen you've got the data or model into the state that you want to explore, you can add in widgets like st.slider(), st.button() or st.selectbox(). It's really straightforward \u2014 treat widgets as variables:\n\nimport streamlit as st\nx = st.slider('x') # \ud83d\udc48 this is a widget\nst.write(x, 'squared is', x * x)\nCopy\n\nOn first run, the app above should output the text \"0 squared is 0\". Then every time a user interacts with a widget, Streamlit simply reruns your script from top to bottom, assigning the current state of the widget to your variable in the process.\n\nFor example, if the user moves the slider to position 10, Streamlit will rerun the code above and set x to 10 accordingly. So now you should see the text \"10 squared is 100\".\n\nWidgets can also be accessed by key, if you choose to specify a string to use as the unique key for the widget:\n\nimport streamlit as st\nst.text_input(\"Your name\", key=\"name\")\n\n# You can access the value at any point with:\nst.session_state.name\nCopy\n\nEvery widget with a key is automatically added to Session State. For more information about Session State, its association with widget state, and its limitations, see Session State API Reference Guide.\n\nUse checkboxes to show/hide data", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-6", "text": "Use checkboxes to show/hide data\n\nOne use case for checkboxes is to hide or show a specific chart or section in an app. st.checkbox() takes a single argument, which is the widget label. In this sample, the checkbox is used to toggle a conditional statement.\n\nimport streamlit as st\nimport numpy as np\nimport pandas as pd\n\nif st.checkbox('Show dataframe'):\n chart_data = pd.DataFrame(\n np.random.randn(20, 3),\n columns=['a', 'b', 'c'])\n\n chart_data\nCopy\nUse a selectbox for options\n\nUse st.selectbox to choose from a series. You can write in the options you want, or pass through an array or data frame column.\n\nLet's use the df data frame we created earlier.\n\nimport streamlit as st\nimport pandas as pd\n\ndf = pd.DataFrame({\n 'first column': [1, 2, 3, 4],\n 'second column': [10, 20, 30, 40]\n })\n\noption = st.selectbox(\n 'Which number do you like best?',\n df['first column'])\n\n'You selected: ', option\nCopy\nLayout\n\nStreamlit makes it easy to organize your widgets in a left panel sidebar with st.sidebar. Each element that's passed to st.sidebar is pinned to the left, allowing users to focus on the content in your app while still having access to UI controls.\n\nFor example, if you want to add a selectbox and a slider to a sidebar, use st.sidebar.slider and st.sidebar.selectbox instead of st.slider and st.selectbox:\n\nimport streamlit as st\n\n# Add a selectbox to the sidebar:\nadd_selectbox = st.sidebar.selectbox(\n 'How would you like to be contacted?',\n ('Email', 'Home phone', 'Mobile phone')\n)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-7", "text": "# Add a slider to the sidebar:\nadd_slider = st.sidebar.slider(\n 'Select a range of values',\n 0.0, 100.0, (25.0, 75.0)\n)\nCopy\n\nBeyond the sidebar, Streamlit offers several other ways to control the layout of your app. st.columns lets you place widgets side-by-side, and st.expander lets you conserve space by hiding away large content.\n\nimport streamlit as st\n\nleft_column, right_column = st.columns(2)\n# You can use a column just like st.sidebar:\nleft_column.button('Press me!')\n\n# Or even better, call Streamlit functions inside a \"with\" block:\nwith right_column:\n chosen = st.radio(\n 'Sorting hat',\n (\"Gryffindor\", \"Ravenclaw\", \"Hufflepuff\", \"Slytherin\"))\n st.write(f\"You are in {chosen} house!\")\nCopy\npush_pin\nNote\n\nst.echo and st.spinner are not currently supported inside the sidebar or layout options. Rest assured, though, we're currently working on adding support for those too!\n\nShow progress\n\nWhen adding long running computations to an app, you can use st.progress() to display status in real time.\n\nFirst, let's import time. We're going to use the time.sleep() method to simulate a long running computation:\n\nimport time\nCopy\n\nNow, let's create a progress bar:\n\nimport streamlit as st\nimport time\n\n'Starting a long computation...'\n\n# Add a placeholder\nlatest_iteration = st.empty()\nbar = st.progress(0)\n\nfor i in range(100):\n # Update the progress bar with each iteration.\n latest_iteration.text(f'Iteration {i+1}')\n bar.progress(i + 1)\n time.sleep(0.1)\n\n'...and now we\\'re done!'\nCopy\nThemes", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-8", "text": "'...and now we\\'re done!'\nCopy\nThemes\n\nStreamlit supports Light and Dark themes out of the box. Streamlit will first check if the user viewing an app has a Light or Dark mode preference set by their operating system and browser. If so, then that preference will be used. Otherwise, the Light theme is applied by default.\n\nYou can also change the active theme from \"\u2630\" \u2192 \"Settings\".\n\nWant to add your own theme to an app? The \"Settings\" menu has a theme editor accessible by clicking on \"Edit active theme\". You can use this editor to try out different colors and see your app update live.\n\nWhen you're happy with your work, themes can be saved by setting config options in the [theme] config section. After you've defined a theme for your app, it will appear as \"Custom Theme\" in the theme selector and will be applied by default instead of the included Light and Dark themes.\n\nMore information about the options available when defining a theme can be found in the theme option documentation.\n\npush_pin\nNote\n\nThe theme editor menu is available only in local development. If you've deployed your app using Streamlit Community Cloud, the \"Edit active theme\" button will no longer be displayed in the \"Settings\" menu.\n\nstar\nTip\n\nAnother way to experiment with different theme colors is to turn on the \"Run on save\" option, edit your config.toml file, and watch as your app reruns with the new theme colors applied.\n\nCaching\n\nThe Streamlit cache allows your app to stay performant even when loading data from the web, manipulating large datasets, or performing expensive computations.\n\nThe basic idea behind caching is to store the results of expensive function calls and return the cached result when the same inputs occur again rather than calling the function on subsequent runs.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-9", "text": "To cache a function in Streamlit, you need to decorate it with one of two decorators (st.cache_data and st.cache_resource):\n\n@st.cache_data\ndef long_running_function(param1, param2):\n return \u2026\nCopy\n\nIn this example, decorating long_running_function with @st.cache_data tells Streamlit that whenever the function is called, it checks two things:\n\nThe values of the input parameters (in this case, param1 and param2).\nThe code inside the function.\n\nIf this is the first time Streamlit sees these parameter values and function code, it runs the function and stores the return value in a cache. The next time the function is called with the same parameters and code (e.g., when a user interacts with the app), Streamlit will skip executing the function altogether and return the cached value instead. During development, the cache updates automatically as the function code changes, ensuring that the latest changes are reflected in the cache.\n\nAs mentioned, there are two caching decorators:\n\nst.cache_data\u00a0is the recommended way to cache computations that return data: loading a DataFrame from CSV, transforming a NumPy array, querying an API, or any other function that returns a serializable data object (str, int, float, DataFrame, array, list, \u2026). It creates a new copy of the data at each function call, making it safe against mutations and race conditions. The behavior of st.cache_data is what you want in most cases \u2013 so if you're unsure, start with\u00a0st.cache_data\u00a0and see if it works!\nst.cache_resource\u00a0is the recommended way to cache global resources like ML models or database connections \u2013 unserializable objects that you don\u2019t want to load multiple times. Using it, you can share these resources across all reruns and sessions of an app without copying or duplication. Note that any mutations to the cached return value directly mutate the object in the cache (more details below).", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-10", "text": "Streamlit's two caching decorators and their use cases.\n\nFor more information about the Streamlit caching decorators, their configuration parameters, and their limitations, see Caching.\n\nPages\n\nAs apps grow large, it becomes useful to organize them into multiple pages. This makes the app easier to manage as a developer and easier to navigate as a user. Streamlit provides a frictionless way to create multipage apps.\n\nWe designed this feature so that building a multipage app is as easy as building a single-page app! Just add more pages to an existing app as follows:\n\nIn the folder containing your main script, create a new pages folder. Let\u2019s say your main script is named main_page.py.\nAdd new .py files in the pages folder to add more pages to your app.\nRun streamlit run main_page.py as usual.\n\nThat\u2019s it! The main_page.py script will now correspond to the main page of your app. And you\u2019ll see the other scripts from the pages folder in the sidebar page selector. For example:\n\nmain_page.py\nimport streamlit as st\n\nst.markdown(\"# Main page \ud83c\udf88\")\nst.sidebar.markdown(\"# Main page \ud83c\udf88\")\nCopy\npages/page_2.py\nimport streamlit as st\n\nst.markdown(\"# Page 2 \u2744\ufe0f\")\nst.sidebar.markdown(\"# Page 2 \u2744\ufe0f\")\nCopy\npages/page_3.py\nimport streamlit as st\n\nst.markdown(\"# Page 3 \ud83c\udf89\")\nst.sidebar.markdown(\"# Page 3 \ud83c\udf89\")\nCopy\n\n\n\nNow run streamlit run main_page.py and view your shiny new multipage app!\n\nOur documentation on Multipage apps teaches you how to add pages to your app, including how to define pages, structure and run multipage apps, and navigate between pages. Once you understand the basics, create your first multipage app!\n\nApp model", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-11", "text": "App model\n\nNow that you know a little more about all the individual pieces, let's close the loop and review how it works together:\n\nStreamlit apps are Python scripts that run from top to bottom\nEvery time a user opens a browser tab pointing to your app, the script is re-executed\nAs the script executes, Streamlit draws its output live in a browser\nScripts use the Streamlit cache to avoid recomputing expensive functions, so updates happen very fast\nEvery time a user interacts with a widget, your script is re-executed and the output value of that widget is set to the new value during that run.\nStreamlit apps can contain multiple pages, which are defined in separate .py files in a pages folder.\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nInstallation\nNext:\nCreate an app\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nMain concepts - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nGet started/\nCreate an app\nCreate an app\n\nIf you've made it this far, chances are you've installed Streamlit and run through the basics in our Main concepts guide. If not, now is a good time to take a look.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-12", "text": "The easiest way to learn how to use Streamlit is to try things out yourself. As you read through this guide, test each method. As long as your app is running, every time you add a new element to your script and save, Streamlit's UI will ask if you'd like to rerun the app and view the changes. This allows you to work in a fast interactive loop: you write some code, save it, review the output, write some more, and so on, until you're happy with the results. The goal is to use Streamlit to create an interactive app for your data or model and along the way to use Streamlit to review, debug, perfect, and share your code.\n\nIn this guide, you're going to use Streamlit's core features to create an interactive app; exploring a public Uber dataset for pickups and drop-offs in New York City. When you're finished, you'll know how to fetch and cache data, draw charts, plot information on a map, and use interactive widgets, like a slider, to filter results.\n\nstar\nTip\n\nIf you'd like to skip ahead and see everything at once, the complete script is available below.\n\nCreate your first app\n\nStreamlit is more than just a way to make data apps, it\u2019s also a community of creators that share their apps and ideas and help each other make their work better. Please come join us on the community forum. We love to hear your questions, ideas, and help you work through your bugs \u2014 stop by today!\n\nThe first step is to create a new Python script. Let's call it uber_pickups.py.\n\nOpen uber_pickups.py in your favorite IDE or text editor, then add these lines:\n\nimport streamlit as st\nimport pandas as pd\nimport numpy as np\nCopy\n\nEvery good app has a title, so let's add one:\n\nst.title('Uber pickups in NYC')\nCopy", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-13", "text": "st.title('Uber pickups in NYC')\nCopy\n\nNow it's time to run Streamlit from the command line:\n\nstreamlit run uber_pickups.py\nCopy\n\nRunning a Streamlit app is no different than any other Python script. Whenever you need to view the app, you can use this command.\n\nstar\nTip\n\nDid you know you can also pass a URL to streamlit run? This is great when combined with GitHub Gists. For example:\n\nstreamlit run https://raw.githubusercontent.com/streamlit/demo-uber-nyc-pickups/master/streamlit_app.py\nCopy\n\nAs usual, the app should automatically open in a new tab in your browser.\n\nFetch some data\n\nNow that you have an app, the next thing you'll need to do is fetch the Uber dataset for pickups and drop-offs in New York City.\n\nLet's start by writing a function to load the data. Add this code to your script:\n\nDATE_COLUMN = 'date/time'\nDATA_URL = ('https://s3-us-west-2.amazonaws.com/'\n 'streamlit-demo-data/uber-raw-data-sep14.csv.gz')\n\ndef load_data(nrows):\n data = pd.read_csv(DATA_URL, nrows=nrows)\n lowercase = lambda x: str(x).lower()\n data.rename(lowercase, axis='columns', inplace=True)\n data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])\n return data\nCopy\n\nYou'll notice that load_data is a plain old function that downloads some data, puts it in a Pandas dataframe, and converts the date column from text to datetime. The function accepts a single parameter (nrows), which specifies the number of rows that you want to load into the dataframe.\n\nNow let's test the function and review the output. Below your function, add these lines:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-14", "text": "Now let's test the function and review the output. Below your function, add these lines:\n\n# Create a text element and let the reader know the data is loading.\ndata_load_state = st.text('Loading data...')\n# Load 10,000 rows of data into the dataframe.\ndata = load_data(10000)\n# Notify the reader that the data was successfully loaded.\ndata_load_state.text('Loading data...done!')\nCopy\n\nYou'll see a few buttons in the upper-right corner of your app asking if you'd like to rerun the app. Choose Always rerun, and you'll see your changes automatically each time you save.\n\nOk, that's underwhelming...\n\nIt turns out that it takes a long time to download data, and load 10,000 lines into a dataframe. Converting the date column into datetime isn\u2019t a quick job either. You don\u2019t want to reload the data each time the app is updated \u2013 luckily Streamlit allows you to cache the data.\n\nEffortless caching\n\nTry adding @st.cache_data before the load_data declaration:\n\n@st.cache_data\ndef load_data(nrows):\nCopy\n\nThen save the script, and Streamlit will automatically rerun your app. Since this is the first time you\u2019re running the script with @st.cache_data, you won't see anything change. Let\u2019s tweak your file a little bit more so that you can see the power of caching.\n\nReplace the line data_load_state.text('Loading data...done!') with this:\n\ndata_load_state.text(\"Done! (using st.cache_data)\")\nCopy\n\nNow save. See how the line you added appeared immediately? If you take a step back for a second, this is actually quite amazing. Something magical is happening behind the scenes, and it only takes one line of code to activate it.\n\nHow's it work?\n\nLet's take a few minutes to discuss how @st.cache_data actually works.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-15", "text": "Let's take a few minutes to discuss how @st.cache_data actually works.\n\nWhen you mark a function with Streamlit\u2019s cache annotation, it tells Streamlit that whenever the function is called that it should check two things:\n\nThe input parameters you used for the function call.\nThe code inside the function.\n\nIf this is the first time Streamlit has seen both these items, with these exact values, and in this exact combination, it runs the function and stores the result in a local cache. The next time the function is called, if the two values haven't changed, then Streamlit knows it can skip executing the function altogether. Instead, it reads the output from the local cache and passes it on to the caller -- like magic.\n\n\"But, wait a second,\" you\u2019re saying to yourself, \"this sounds too good to be true. What are the limitations of all this awesomesauce?\"\n\nWell, there are a few:\n\nStreamlit will only check for changes within the current working directory. If you upgrade a Python library, Streamlit's cache will only notice this if that library is installed inside your working directory.\nIf your function is not deterministic (that is, its output depends on random numbers), or if it pulls data from an external time-varying source (for example, a live stock market ticker service) the cached value will be none-the-wiser.\nLastly, you should avoid mutating the output of a function cached with st.cache_data since cached values are stored by reference.\n\nWhile these limitations are important to keep in mind, they tend not to be an issue a surprising amount of the time. Those times, this cache is really transformational.\n\nstar\nTip\n\nWhenever you have a long-running computation in your code, consider refactoring it so you can use @st.cache_data, if possible. Please read Caching for more details.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-16", "text": "Now that you know how caching with Streamlit works, let\u2019s get back to the Uber pickup data.\n\nInspect the raw data\n\nIt's always a good idea to take a look at the raw data you're working with before you start working with it. Let's add a subheader and a printout of the raw data to the app:\n\nst.subheader('Raw data')\nst.write(data)\nCopy\n\nIn the Main concepts guide you learned that st.write will render almost anything you pass to it. In this case, you're passing in a dataframe and it's rendering as an interactive table.\n\nst.write tries to do the right thing based on the data type of the input. If it isn't doing what you expect you can use a specialized command like st.dataframe instead. For a full list, see API reference.\n\nDraw a histogram\n\nNow that you've had a chance to take a look at the dataset and observe what's available, let's take things a step further and draw a histogram to see what Uber's busiest hours are in New York City.\n\nTo start, let's add a subheader just below the raw data section:\n\nst.subheader('Number of pickups by hour')\nCopy\n\nUse NumPy to generate a histogram that breaks down pickup times binned by hour:\n\nhist_values = np.histogram(\n data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]\nCopy\n\nNow, let's use Streamlit's st.bar_chart() method to draw this histogram.\n\nst.bar_chart(hist_values)\nCopy\n\nSave your script. This histogram should show up in your app right away. After a quick review, it looks like the busiest time is 17:00 (5 P.M.).", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-17", "text": "To draw this diagram we used Streamlit's native bar_chart() method, but it's important to know that Streamlit supports more complex charting libraries like Altair, Bokeh, Plotly, Matplotlib and more. For a full list, see supported charting libraries.\n\nPlot data on a map\n\nUsing a histogram with Uber's dataset helped us determine what the busiest times are for pickups, but what if we wanted to figure out where pickups were concentrated throughout the city. While you could use a bar chart to show this data, it wouldn't be easy to interpret unless you were intimately familiar with latitudinal and longitudinal coordinates in the city. To show pickup concentration, let's use Streamlit st.map() function to overlay the data on a map of New York City.\n\nAdd a subheader for the section:\n\nst.subheader('Map of all pickups')\nCopy\n\nUse the st.map() function to plot the data:\n\nst.map(data)\nCopy\n\nSave your script. The map is fully interactive. Give it a try by panning or zooming in a bit.\n\nAfter drawing your histogram, you determined that the busiest hour for Uber pickups was 17:00. Let's redraw the map to show the concentration of pickups at 17:00.\n\nLocate the following code snippet:\n\nst.subheader('Map of all pickups')\nst.map(data)\nCopy\n\nReplace it with:\n\nhour_to_filter = 17\nfiltered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]\nst.subheader(f'Map of all pickups at {hour_to_filter}:00')\nst.map(filtered_data)\nCopy\n\nYou should see the data update instantly.\n\nTo draw this map we used the st.map function that's built into Streamlit, but if you'd like to visualize complex map data, we encourage you to take a look at the st.pydeck_chart.\n\nFilter results with a slider", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-18", "text": "Filter results with a slider\n\nIn the last section, when you drew the map, the time used to filter results was hardcoded into the script, but what if we wanted to let a reader dynamically filter the data in real time? Using Streamlit's widgets you can. Let's add a slider to the app with the st.slider() method.\n\nLocate hour_to_filter and replace it with this code snippet:\n\nhour_to_filter = st.slider('hour', 0, 23, 17) # min: 0h, max: 23h, default: 17h\nCopy\n\nUse the slider and watch the map update in real time.\n\nUse a button to toggle data\n\nSliders are just one way to dynamically change the composition of your app. Let's use the st.checkbox function to add a checkbox to your app. We'll use this checkbox to show/hide the raw data table at the top of your app.\n\nLocate these lines:\n\nst.subheader('Raw data')\nst.write(data)\nCopy\n\nReplace these lines with the following code:\n\nif st.checkbox('Show raw data'):\n st.subheader('Raw data')\n st.write(data)\nCopy\n\nWe're sure you've got your own ideas. When you're done with this tutorial, check out all the widgets that Streamlit exposes in our API Reference.\n\nLet's put it all together\n\nThat's it, you've made it to the end. Here's the complete script for our interactive app.\n\nstar\nTip\n\nIf you've skipped ahead, after you've created your script, the command to run Streamlit is streamlit run [app name].\n\nimport streamlit as st\nimport pandas as pd\nimport numpy as np\n\nst.title('Uber pickups in NYC')", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-19", "text": "st.title('Uber pickups in NYC')\n\nDATE_COLUMN = 'date/time'\nDATA_URL = ('https://s3-us-west-2.amazonaws.com/'\n 'streamlit-demo-data/uber-raw-data-sep14.csv.gz')\n\n@st.cache_data\ndef load_data(nrows):\n data = pd.read_csv(DATA_URL, nrows=nrows)\n lowercase = lambda x: str(x).lower()\n data.rename(lowercase, axis='columns', inplace=True)\n data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])\n return data\n\ndata_load_state = st.text('Loading data...')\ndata = load_data(10000)\ndata_load_state.text(\"Done! (using st.cache_data)\")\n\nif st.checkbox('Show raw data'):\n st.subheader('Raw data')\n st.write(data)\n\nst.subheader('Number of pickups by hour')\nhist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]\nst.bar_chart(hist_values)\n\n# Some number in the range 0-23\nhour_to_filter = st.slider('hour', 0, 23, 17)\nfiltered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]\n\nst.subheader('Map of all pickups at %s:00' % hour_to_filter)\nst.map(filtered_data)\nCopy\nShare your app\n\nAfter you\u2019ve built a Streamlit app, it's time to share it! To show it off to the world you can use Streamlit Community Cloud to deploy, manage, and share your app for free.\n\nIt works in 3 simple steps:\n\nPut your app in a public GitHub repo (and make sure it has a requirements.txt!)\nSign into share.streamlit.io\nClick 'Deploy an app' and then paste in your GitHub URL", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-20", "text": "That's it! \ud83c\udf88 You now have a publicly deployed app that you can share with the world. Click to learn more about how to use Streamlit Community Cloud.\n\nGet help\n\nThat's it for getting started, now you can go and build your own apps! If you run into difficulties here are a few things you can do.\n\nCheck out our community forum and post a question\nQuick help from command line with streamlit help\nGo through our Knowledge Base for tips, step-by-step tutorials, and articles that answer your questions about creating and deploying Streamlit apps.\nRead more documentation! Check out:\nAdvanced features for things like caching, theming, and adding statefulness to apps.\nAPI reference for examples of every Streamlit command.\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nMain concepts\nNext:\nMultipage apps\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nCreate an app - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nKnowledge base/\nTutorials/\nConnect to data sources/\nGoogle Cloud Storage\nConnect Streamlit to Google Cloud Storage\nIntroduction\n\nThis guide explains how to securely access files on Google Cloud Storage from Streamlit Community Cloud. It uses the google-cloud-storage library and Streamlit's secrets management.\n\nCreate a Google Cloud Storage bucket and add a file\npush_pin\nNote\n\nIf you already have a bucket that you want to use, feel free to skip to the next step.\n\nFirst, sign up for Google Cloud Platform or log in. Go to the Google Cloud Storage console and create a new bucket.\n\nNavigate to the upload section of your new bucket:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-21", "text": "Navigate to the upload section of your new bucket:\n\nAnd upload the following CSV file, which contains some example data:\n\nmyfile.csv\nEnable the Google Cloud Storage API\n\nThe Google Cloud Storage API is enabled by default when you create a project through the Google Cloud Console or CLI. Feel free to skip to the next step.\n\nIf you do need to enable the API for programmatic access in your project, head over to the APIs & Services dashboard (select or create a project if asked). Search for the Cloud Storage API and enable it. The screenshot below has a blue \"Manage\" button and indicates the \"API is enabled\" which means no further action needs to be taken. This is very likely what you have since the API is enabled by default. However, if that is not what you see and you have an \"Enable\" button, you'll need to enable the API:\n\nCreate a service account and key file\n\nTo use the Google Cloud Storage API from Streamlit Community Cloud, you need a Google Cloud Platform service account (a special type for programmatic data access). Go to the Service Accounts page and create an account with Viewer permission.\n\npush_pin\nNote\n\nIf the button CREATE SERVICE ACCOUNT is gray, you don't have the correct permissions. Ask the admin of your Google Cloud project for help.\n\nAfter clicking DONE, you should be back on the service accounts overview. Create a JSON key file for the new account and download it:\n\nAdd the key to your local app secrets\n\nYour local Streamlit app will read secrets from a file .streamlit/secrets.toml in your app's root directory. Create this file if it doesn't exist yet and add the access key to it as shown below:\n\n# .streamlit/secrets.toml", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-22", "text": "# .streamlit/secrets.toml\n\n[gcp_service_account]\ntype = \"service_account\"\nproject_id = \"xxx\"\nprivate_key_id = \"xxx\"\nprivate_key = \"xxx\"\nclient_email = \"xxx\"\nclient_id = \"xxx\"\nauth_uri = \"https://accounts.google.com/o/oauth2/auth\"\ntoken_uri = \"https://oauth2.googleapis.com/token\"\nauth_provider_x509_cert_url = \"https://www.googleapis.com/oauth2/v1/certs\"\nclient_x509_cert_url = \"xxx\"\nCopy\npriority_high\nImportant\n\nAdd this file to .gitignore and don't commit it to your GitHub repo!\n\nCopy your app secrets to the cloud\n\nAs the secrets.toml file above is not committed to GitHub, you need to pass its content to your deployed app (on Streamlit Community Cloud) separately. Go to the app dashboard and in the app's dropdown menu, click on Edit Secrets. Copy the content of secrets.toml into the text area. More information is available at Secrets Management.\n\nAdd google-cloud-storage to your requirements file\n\nAdd the google-cloud-storage package to your requirements.txt file, preferably pinning its version (replace x.x.x with the version you want installed):\n\n# requirements.txt\ngoogle-cloud-storage==x.x.x\nCopy\nWrite your Streamlit app\n\nCopy the code below to your Streamlit app and run it. Make sure to adapt the name of your bucket and file. Note that Streamlit automatically turns the access keys from your secrets file into environment variables.\n\n# streamlit_app.py\n\nimport streamlit as st\nfrom google.oauth2 import service_account\nfrom google.cloud import storage\n\n# Create API client.\ncredentials = service_account.Credentials.from_service_account_info(\n st.secrets[\"gcp_service_account\"]\n)\nclient = storage.Client(credentials=credentials)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-23", "text": "# Retrieve file contents.\n# Uses st.cache_data to only rerun when the query changes or after 10 min.\n@st.cache_data(ttl=600)\ndef read_file(bucket_name, file_path):\n bucket = client.bucket(bucket_name)\n content = bucket.blob(file_path).download_as_string().decode(\"utf-8\")\n return content\n\nbucket_name = \"streamlit-bucket\"\nfile_path = \"myfile.csv\"\n\ncontent = read_file(bucket_name, file_path)\n\n# Print results.\nfor line in content.strip().split(\"\\n\"):\n name, pet = line.split(\",\")\n st.write(f\"{name} has a :{pet}:\")\nCopy\n\nSee st.cache_data above? Without it, Streamlit would run the query every time the app reruns (e.g. on a widget interaction). With st.cache_data, it only runs when the query changes or after 10 minutes (that's what ttl is for). Watch out: If your database updates more frequently, you should adapt ttl or remove caching so viewers always see the latest data. Learn more in Caching.\n\nIf everything worked out (and you used the example file given above), your app should look like this:\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nFirestore\nNext:\nMicrosoft SQL Server\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nConnect Streamlit to Google Cloud Storage - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nCheat sheet\nCheat Sheet\n\nThis is a summary of the docs, as of Streamlit v1.20.0.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-24", "text": "This is a summary of the docs, as of Streamlit v1.20.0.\n\nInstall & Import\nstreamlit run first_app.py\n\n# Import convention\n>>> import streamlit as st\nCommand line\nstreamlit --help\nstreamlit run your_script.py\nstreamlit hello\nstreamlit config show\nstreamlit cache clear\nstreamlit docs\nstreamlit --version\nPre-release features\npip uninstall streamlit\npip install streamlit-nightly --upgrade\n\nLearn more about experimental features\n\nMagic commands\n# Magic commands implicitly\n# call st.write().\n'_This_ is some **Markdown***'\nmy_variable\n'dataframe:', my_data_frame\nDisplay text\nst.text('Fixed width text')\nst.markdown('_Markdown_') # see *\nst.latex(r''' e^{i\\pi} + 1 = 0 ''')\nst.write('Most objects') # df, err, func, keras!\nst.write(['st', 'is <', 3]) # see *\nst.title('My title')\nst.header('My header')\nst.subheader('My sub')\nst.code('for i in range(8): foo()')\n* optional kwarg unsafe_allow_html = True\nDisplay data\nst.dataframe(my_dataframe)\nst.table(data.iloc[0:10])\nst.json({'foo':'bar','fu':'ba'})\nst.metric('My metric', 42, 2)\nDisplay media\nst.image('./header.png')\nst.audio(data)\nst.video(data)\nAdd widgets to sidebar\n# Just add it after st.sidebar:\n>>> a = st.sidebar.radio('Select one:', [1, 2])", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-25", "text": "# Or use \"with\" notation:\n>>> with st.sidebar:\n>>> st.radio('Select one:', [1, 2])\nColumns\n# Two equal columns:\n>>> col1, col2 = st.columns(2)\n>>> col1.write(\"This is column 1\")\n>>> col2.write(\"This is column 2\")\n\n# Three different columns:\n>>> col1, col2, col3 = st.columns([3, 1, 1])\n# col1 is larger.\n\n# You can also use \"with\" notation:\n>>> with col1:\n>>> st.radio('Select one:', [1, 2])\nTabs\n# Insert containers separated into tabs:\n>>> tab1, tab2 = st.tabs([\"Tab 1\", \"Tab2\"])\n>>> tab1.write(\"this is tab 1\")\n>>> tab2.write(\"this is tab 2\")\n\n# You can also use \"with\" notation:\n>>> with tab1:\n>>> st.radio('Select one:', [1, 2])\nControl flow\n# Stop execution immediately:\nst.stop()\n# Rerun script immediately:\nst.experimental_rerun()", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-26", "text": "# Group multiple widgets:\n>>> with st.form(key='my_form'):\n>>> username = st.text_input('Username')\n>>> password = st.text_input('Password')\n>>> st.form_submit_button('Login')\nDisplay interactive widgets\nst.button('Click me')\nst.experimental_data_editor('Edit data', data)\nst.checkbox('I agree')\nst.radio('Pick one', ['cats', 'dogs'])\nst.selectbox('Pick one', ['cats', 'dogs'])\nst.multiselect('Buy', ['milk', 'apples', 'potatoes'])\nst.slider('Pick a number', 0, 100)\nst.select_slider('Pick a size', ['S', 'M', 'L'])\nst.text_input('First name')\nst.number_input('Pick a number', 0, 10)\nst.text_area('Text to translate')\nst.date_input('Your birthday')\nst.time_input('Meeting time')\nst.file_uploader('Upload a CSV')\nst.download_button('Download file', data)\nst.camera_input(\"Take a picture\")\nst.color_picker('Pick a color')\n\n# Use widgets' returned values in variables:\n>>> for i in range(int(st.number_input('Num:'))):\n>>> foo()\n>>> if st.sidebar.selectbox('I:',['f']) == 'f':\n>>> b()\n>>> my_slider_val = st.slider('Quinn Mallory', 1, 88)\n>>> st.write(slider_val)\n\n# Disable widgets to remove interactivity:\n>>> st.slider('Pick a number', 0, 100, disabled=True)\nMutate data\n# Add rows to a dataframe after\n# showing it.\n>>> element = st.dataframe(df1)\n>>> element.add_rows(df2)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-27", "text": "# Add rows to a chart after\n# showing it.\n>>> element = st.line_chart(df1)\n>>> element.add_rows(df2)\nDisplay code\n>>> with st.echo():\n>>> st.write('Code will be executed and printed')\nPlaceholders, help, and options\n# Replace any single element.\n>>> element = st.empty()\n>>> element.line_chart(...)\n>>> element.text_input(...) # Replaces previous.\n\n# Insert out of order.\n>>> elements = st.container()\n>>> elements.line_chart(...)\n>>> st.write(\"Hello\")\n>>> elements.text_input(...) # Appears above \"Hello\".", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-28", "text": "st.help(pandas.DataFrame)\nst.get_option(key)\nst.set_option(key, value)\nst.set_page_config(layout='wide')\nst.experimental_show(objects)\nst.experimental_get_query_params()\nst.experimental_set_query_params(**params)\nOptimize performance\nCache data objects\n# E.g. Dataframe computation, storing downloaded data, etc.\n>>> @st.cache_data\n... def foo(bar):\n... # Do something expensive and return data\n... return data\n# Executes foo\n>>> d1 = foo(ref1)\n# Does not execute foo\n# Returns cached item by value, d1 == d2\n>>> d2 = foo(ref1)\n# Different arg, so function foo executes\n>>> d3 = foo(ref2)\n# Clear all cached entries for this function\n>>> foo.clear()\n# Clear values from *all* in-memory or on-disk cached functions\n>>> st.cache_data.clear()\nCache global resources\n# E.g. TensorFlow session, database connection, etc.\n>>> @st.cache_resource\n... def foo(bar):\n... # Create and return a non-data object\n... return session\n# Executes foo\n>>> s1 = foo(ref1)\n# Does not execute foo\n# Returns cached item by reference, s1 == s2\n>>> s2 = foo(ref1)\n# Different arg, so function foo executes\n>>> s3 = foo(ref2)\n# Clear all cached entries for this function\n>>> foo.clear()\n# Clear all global resources from cache\n>>> st.cache_resource.clear()\nDeprecated caching\n>>> @st.cache\n... def foo(bar):\n... # Do something expensive in here...\n... return data\n>>> # Executes foo\n>>> d1 = foo(ref1)\n>>> # Does not execute foo\n>>> # Returns cached item by reference, d1 == d2", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-29", "text": ">>> # Does not execute foo\n>>> # Returns cached item by reference, d1 == d2\n>>> d2 = foo(ref1)\n>>> # Different arg, so function foo executes\n>>> d3 = foo(ref2)\nDisplay progress and status\n>>> with st.spinner(text='In progress'):\n>>> time.sleep(5)\n>>> st.success('Done')", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-30", "text": "st.progress(progress_variable_1_to_100)\nst.balloons()\nst.snow()\nst.error('Error message')\nst.warning('Warning message')\nst.info('Info message')\nst.success('Success message')\nst.exception(e)\nPersonalize apps for users\n# Show different content based on the user's email address.\n>>> if st.user.email == 'jane@email.com':\n>>> display_jane_content()\n>>> elif st.user.email == 'adam@foocorp.io':\n>>> display_adam_content()\n>>> else:\n>>> st.write(\"Please contact us to get access!\")\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nChangelog\nNext:\nStreamlit Community Cloud\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nCheat sheet - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAdvanced features/\nAdd statefulness to apps\nAdd statefulness to apps\nWhat is State?\n\nWe define access to a Streamlit app in a browser tab as a session. For each browser tab that connects to the Streamlit server, a new session is created. Streamlit reruns your script from top to bottom every time you interact with your app. Each reruns takes place in a blank slate: no variables are shared between runs.\n\nSession State is a way to share variables between reruns, for each user session. In addition to the ability to store and persist state, Streamlit also exposes the ability to manipulate state using Callbacks. Session state also persists across apps inside a multipage app.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-31", "text": "In this guide, we will illustrate the usage of Session State and Callbacks as we build a stateful Counter app.\n\nFor details on the Session State and Callbacks API, please refer to our Session State API Reference Guide.\n\nAlso, check out this Session State basics tutorial video by Streamlit Developer Advocate Dr. Marisa Smith to get started:\n\nBuild a Counter\n\nLet's call our script counter.py. It initializes a count variable and has a button to increment the value stored in the count variable:\n\nimport streamlit as st\n\nst.title('Counter Example')\ncount = 0\n\nincrement = st.button('Increment')\nif increment:\n count += 1\n\nst.write('Count = ', count)\nCopy\n\nNo matter how many times we press the Increment button in the above app, the count remains at 1. Let's understand why:\n\nEach time we press the Increment button, Streamlit reruns counter.py from top to bottom, and with every run, count gets initialized to 0 .\nPressing Increment subsequently adds 1 to 0, thus count=1 no matter how many times we press Increment.\n\nAs we'll see later, we can avoid this issue by storing count as a Session State variable. By doing so, we're indicating to Streamlit that it should maintain the value stored inside a Session State variable across app reruns.\n\nLet's learn more about the API to use Session State.\n\nInitialization\n\nThe Session State API follows a field-based API, which is very similar to Python dictionaries:\n\nimport streamlit as st\n\n# Check if 'key' already exists in session_state\n# If not, then initialize it\nif 'key' not in st.session_state:\n st.session_state['key'] = 'value'\n\n# Session State also supports the attribute based syntax\nif 'key' not in st.session_state:\n st.session_state.key = 'value'\nCopy\nReads and updates", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-32", "text": "Read the value of an item in Session State by passing the item to st.write :\n\nimport streamlit as st\n\nif 'key' not in st.session_state:\n st.session_state['key'] = 'value'\n\n# Reads\nst.write(st.session_state.key)\n\n# Outputs: value\nCopy\n\nUpdate an item in Session State by assigning it a value:\n\nimport streamlit as st\n\nif 'key' not in st.session_state:\n st.session_state['key'] = 'value'\n\n# Updates\nst.session_state.key = 'value2' # Attribute API\nst.session_state['key'] = 'value2' # Dictionary like API\nCopy\n\nStreamlit throws an exception if an uninitialized variable is accessed:\n\nimport streamlit as st\n\nst.write(st.session_state['value'])\n\n# Throws an exception!\nCopy\n\nLet's now take a look at a few examples that illustrate how to add Session State to our Counter app.\n\nExample 1: Add Session State\n\nNow that we've got a hang of the Session State API, let's update our Counter app to use Session State:\n\nimport streamlit as st\n\nst.title('Counter Example')\nif 'count' not in st.session_state:\n st.session_state.count = 0\n\nincrement = st.button('Increment')\nif increment:\n st.session_state.count += 1\n\nst.write('Count = ', st.session_state.count)\nCopy\n\nAs you can see in the above example, pressing the Increment button updates the count each time.\n\nExample 2: Session State and Callbacks\n\nNow that we've built a basic Counter app using Session State, let's move on to something a little more complex. The next example uses Callbacks with Session State.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-33", "text": "Callbacks: A callback is a Python function which gets called when an input widget changes. Callbacks can be used with widgets using the parameters on_change (or on_click), args, and kwargs. The full Callbacks API can be found in our Session State API Reference Guide.\n\nimport streamlit as st\n\nst.title('Counter Example using Callbacks')\nif 'count' not in st.session_state:\n st.session_state.count = 0\n\ndef increment_counter():\n st.session_state.count += 1\n\nst.button('Increment', on_click=increment_counter)\n\nst.write('Count = ', st.session_state.count)\nCopy\n\nNow, pressing the Increment button updates the count each time by calling the increment_counter() function.\n\nExample 3: Use args and kwargs in Callbacks\n\nCallbacks also support passing arguments using the args parameter in a widget:\n\nimport streamlit as st\n\nst.title('Counter Example using Callbacks with args')\nif 'count' not in st.session_state:\n st.session_state.count = 0\n\nincrement_value = st.number_input('Enter a value', value=0, step=1)\n\ndef increment_counter(increment_value):\n st.session_state.count += increment_value\n\nincrement = st.button('Increment', on_click=increment_counter,\n args=(increment_value, ))\n\nst.write('Count = ', st.session_state.count)\nCopy\n\nAdditionally, we can also use the kwargs parameter in a widget to pass named arguments to the callback function as shown below:\n\nimport streamlit as st\n\nst.title('Counter Example using Callbacks with kwargs')\nif 'count' not in st.session_state:\n st.session_state.count = 0\n\ndef increment_counter(increment_value=0):\n st.session_state.count += increment_value\n\ndef decrement_counter(decrement_value=0):\n st.session_state.count -= decrement_value\n\nst.button('Increment', on_click=increment_counter,\n kwargs=dict(increment_value=5))", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-34", "text": "st.button('Increment', on_click=increment_counter,\n kwargs=dict(increment_value=5))\n\nst.button('Decrement', on_click=decrement_counter,\n kwargs=dict(decrement_value=1))\n\nst.write('Count = ', st.session_state.count)\nCopy\nExample 4: Forms and Callbacks\n\nSay we now want to not only increment the count, but also store when it was last updated. We illustrate doing this using Callbacks and st.form:\n\nimport streamlit as st\nimport datetime\n\nst.title('Counter Example')\nif 'count' not in st.session_state:\n st.session_state.count = 0\n st.session_state.last_updated = datetime.time(0,0)\n\ndef update_counter():\n st.session_state.count += st.session_state.increment_value\n st.session_state.last_updated = st.session_state.update_time\n\nwith st.form(key='my_form'):\n st.time_input(label='Enter the time', value=datetime.datetime.now().time(), key='update_time')\n st.number_input('Enter a value', value=0, step=1, key='increment_value')\n submit = st.form_submit_button(label='Update', on_click=update_counter)\n\nst.write('Current Count = ', st.session_state.count)\nst.write('Last Updated = ', st.session_state.last_updated)\nCopy\nAdvanced concepts\nSession State and Widget State association\n\nSession State provides the functionality to store variables across reruns. Widget state (i.e. the value of a widget) is also stored in a session.\n\nFor simplicity, we have unified this information in one place. i.e. the Session State. This convenience feature makes it super easy to read or write to the widget's state anywhere in the app's code. Session State variables mirror the widget value using the key argument.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-35", "text": "We illustrate this with the following example. Let's say we have an app with a slider to represent temperature in Celsius. We can set and get the value of the temperature widget by using the Session State API, as follows:\n\nimport streamlit as st\n\nif \"celsius\" not in st.session_state:\n # set the initial default value of the slider widget\n st.session_state.celsius = 50.0\n\nst.slider(\n \"Temperature in Celsius\",\n min_value=-100.0,\n max_value=100.0,\n key=\"celsius\"\n)\n\n# This will get the value of the slider widget\nst.write(st.session_state.celsius)\nCopy\n\nThere is a limitation to setting widget values using the Session State API.\n\npriority_high\nImportant\n\nStreamlit does not allow setting widget values via the Session State API for st.button and st.file_uploader.\n\nThe following example will raise a StreamlitAPIException on trying to set the state of st.button via the Session State API:\n\nimport streamlit as st\n\nif 'my_button' not in st.session_state:\n st.session_state.my_button = True\n # Streamlit will raise an Exception on trying to set the state of button\n\nst.button('Submit', key='my_button')\nCopy\nCaveats and limitations\n\nHere are some limitations to keep in mind when using Session State:\n\nSession State exists for as long as the tab is open and connected to the Streamlit server. As soon as you close the tab, everything stored in Session State is lost.\nSession State is not persisted. If the Streamlit server crashes, then everything stored in Session State gets wiped\nFor caveats and limitations with the Session State API, please see the API limitations.\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-36", "text": "Our forums are full of helpful information and Streamlit experts.\n\nPrevious:\nExperimental cache primitives\nNext:\nDataframes\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nAdd statefulness to apps - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAdvanced features/\nDataframes\nDataframes\n\nDataframes are a great way to display and edit data in a tabular format. Working with Pandas DataFrames and other tabular data structures is key to data science workflows. If developers and data scientists want to display this data in Streamlit, they have multiple options: st.dataframe and st.experimental_data_editor. If you want to solely display data in a table-like UI, st.dataframe is the way to go. If you want to interactively edit data, use st.experimental_data_editor. We explore the use cases and advantages of each option in the following sections.\n\nDisplay dataframes with st.dataframe\n\nStreamlit can display dataframes in a table-like UI via st.dataframe :\n\nimport streamlit as st\nimport pandas as pd\n\ndf = pd.DataFrame(\n [\n {\"command\": \"st.selectbox\", \"rating\": 4, \"is_widget\": True},\n {\"command\": \"st.balloons\", \"rating\": 5, \"is_widget\": False},\n {\"command\": \"st.time_input\", \"rating\": 3, \"is_widget\": True},\n ]\n)\n\nst.dataframe(df, use_container_width=True)\nCopy\n(view standalone Streamlit app)\nAdditional UI features\n\nst.dataframe also provides some additional functionality by using glide-data-grid under the hood:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-37", "text": "st.dataframe also provides some additional functionality by using glide-data-grid under the hood:\n\nColumn sorting: sort columns by clicking on their headers.\nColumn resizing: resize columns by dragging and dropping column header borders.\nTable resizing: resize tables by dragging and dropping the bottom right corner.\nSearch: search through data by clicking a table, using hotkeys (\u2318 Cmd + F\u00a0or\u00a0Ctrl + F) to bring up the search bar, and using the search bar to filter data.\nCopy to clipboard: select one or multiple cells, copy them to the clipboard and paste them into your favorite spreadsheet software.\n\nTry out all the addition UI features using the embedded app from the prior section.\n\nIn addition to Pandas DataFrames, st.dataframe also supports other common Python types, e.g., list, dict, or numpy array. It also supports Snowpark and PySpark DataFrames, which allow you to lazily evaluate and pull data from databases. This can be useful for working with large datasets.\n\nEdit data with st.experimental_data_editor\n\nStreamlit supports editable dataframes via the st.experimental_data_editor command. Check out its API in st.experimental_data_editor. It shows the dataframe in a table, similar to st.dataframe. But in contrast to st.dataframe, this table isn't static! The user can click on cells and edit them. The edited data is then returned on the Python side. Here's an example:\n\ndf = pd.DataFrame(\n [\n {\"command\": \"st.selectbox\", \"rating\": 4, \"is_widget\": True},\n {\"command\": \"st.balloons\", \"rating\": 5, \"is_widget\": False},\n {\"command\": \"st.time_input\", \"rating\": 3, \"is_widget\": True},\n ]\n)\n\ndf = load_data()\nedited_df = st.experimental_data_editor(df) # \ud83d\udc48 An editable dataframe", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-38", "text": "df = load_data()\nedited_df = st.experimental_data_editor(df) # \ud83d\udc48 An editable dataframe\n\nfavorite_command = edited_df.loc[edited_df[\"rating\"].idxmax()][\"command\"]\nst.markdown(f\"Your favorite command is **{favorite_command}** \ud83c\udf88\")\nCopy\nView interactive app\nexpand_more\n\nTry it out by double-clicking on any cell. You'll notice you can edit all cell values. Try editing the values in the rating column and observe how the text output at the bottom changes:\n\nst.experimental_data_editor also supports a few additional things:\n\nCopy and paste support from and to Excel and Google Sheets.\nAdd and delete rows. You can do this by setting num_rows= \"dynamic\" when calling st.experimental_data_editor. This will allow users to add and delete rows as needed.\nAccess edited data.\nBulk edits (similar to Excel, just drag a handle to edit neighboring cells).\nAutomatic input validation, e.g. no way to enter letters into a number cell.\nEdit common data structures such as lists, dicts, NumPy ndarray, etc.\nCopy and paste support\n\nThe data editor supports pasting in tabular data from Google Sheets, Excel, Notion, and many other similar tools. You can also copy-paste data between\u00a0st.experimental_data_editor instances. This can be a huge time saver for users who need to work with data across multiple platforms. To try it out:\n\nCopy data from\u00a0this Google Sheets document\u00a0to clipboard\nSelect any cell in the\u00a0name\u00a0column of the table below and paste it in (via\u00a0ctrl/cmd + v).\nView interactive app\nexpand_more\npush_pin\nNote\n\nEvery cell of the pasted data will be evaluated individually and inserted into the cells if the data is compatible with the column type. E.g., pasting in non-numerical text data into a number column will be ignored.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-39", "text": "Did you notice that although the initial dataframe had just five rows, pasting all those rows from the spreadsheet added additional rows to the dataframe? \ud83d\udc40\u00a0Let's find out how that works in the next section.\n\nAdd and delete rows\n\nWith st.experimental_data_editor, viewers can add or delete rows via the table UI. This mode can be activated by setting the\u00a0num_rows parameter to\u00a0\"dynamic\". E.g.\n\nedited_df = st.experimental_data_editor(df, num_rows=\u201ddynamic\u201d)\nCopy\nTo add new rows, scroll to the bottom-most row and click on the \u201c+\u201d sign in any cell.\nTo delete rows, select one or more rows and press the delete key on your keyboard.\nView interactive app\nexpand_more\nAccess edited data\n\nSometimes, it is more convenient to know which cells have been changed rather than getting the entire edited dataframe back. Streamlit makes this easy through the use of session state. If a key parameter is set, Streamlit will store any changes made to the dataframe in the session state.\n\nThis snippet shows how you can access changed data using session state:\n\nst.experimental_data_editor(df, key=\"data_editor\") # \ud83d\udc48 Set a key\nst.write(\"Here's the session state:\")\nst.write(st.session_state[\"data_editor\"]) # \ud83d\udc48 Access the edited data\nCopy\n\nIn this code snippet, the key parameter is set to \"data_editor\". Any changes made to the data in the st.experimental_data_editor instance will be tracked by Streamlit and stored in session state under the key \"data_editor\".\n\nAfter the data editor is created, the contents of the \"data_editor\" key in session state are printed to the screen using st.write(st.session_state[\"data_editor\"]). This allows you to see the changes made to the original dataframe without having to return the entire dataframe from the data editor.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-40", "text": "This can be useful when working with large dataframes and you only need to know which cells have changed, rather than the entire edited dataframe.\n\nView interactive app\nexpand_more\n\nUse all we've learned so far and apply them to the above embedded app. Try editing cells, adding new rows, and deleting rows.\n\nNotice how edits to the table are reflected in session state: when you make any edits, a rerun is triggered which sends the edits to the backend via st.experimental_data_editor's keyed widget state. Its widget state is a JSON object containing three properties: edited_cells, added_rows, and deleted rows:.\n\nedited_cells maps a cell position to the edited value: column:row \u2192 value .\nadded_rows is a list of newly added rows to the table. Each row is a dictionary where the keys are the column indices and the values are the corresponding cell values.\ndeleted_rows is a list of row indices that have been deleted from the table.\nBulk edits\n\nThe data editor includes a feature that allows for bulk editing of cells. Similar to Excel, you can drag a handle across a selection of cells to edit their values in bulk. You can even apply commonly used keyboard shortcuts in spreadsheet software. This is useful when you need to make the same change across multiple cells, rather than editing each cell individually:\n\nAutomatic input validation\n\nThe data editor includes automatic input validation to help prevent errors when editing cells. For example, if you have a column that contains numerical data, the input field will automatically restrict the user to only entering numerical data. This helps to prevent errors that could occur if the user were to accidentally enter a non-numerical value.\n\nEdit common data structures", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-41", "text": "Edit common data structures\n\nEditing doesn't just work for Pandas DataFrames! You can also edit lists, tuples, sets, dictionaries, NumPy arrays, or Snowpark & PySpark DataFrames. Most data types will be returned in their original format. But some types (e.g. Snowpark and PySpark) are converted to Pandas DataFrames. To learn about all the supported types, read the st.experimental_data_editor API.\n\nE.g. you can easily let the user add items to a list:\n\nedited_list = st.experimental_data_editor([\"red\", \"green\", \"blue\"], num_rows= \"dynamic\")\nst.write(\"Here are all the colors you entered:\")\nst.write(edited_list)\nCopy\n\nOr numpy arrays:\n\nimport numpy as np\n\nst.experimental_data_editor(np.array([\n [\"st.text_area\", \"widget\", 4.92],\n [\"st.markdown\", \"element\", 47.22]\n]))\nCopy\n\nOr lists of records:\n\nst.experimental_data_editor([\n {\"name\": \"st.text_area\", \"type\": \"widget\"},\n {\"name\": \"st.markdown\", \"type\": \"element\"},\n])\nCopy\n\nOr dictionaries and many more types!\n\nst.experimental_data_editor({\n \"st.text_area\": \"widget\",\n \"st.markdown\": \"element\"\n})\nCopy\nConfiguring columns\n\nYou will be able configure the display and editing behavior of columns via st.dataframe and st.experimental_data_editor in to-be-announced future releases. We are developing an API to let you add images, charts, and clickable URLs in dataframe columns. Additionally, you will be able to make individual columns editable, set columns as categorical and specify which options they can take, hide the index of the dataframe, and much more.\n\npriority_high\nImportant\n\nWe will release the ability to configure columns in a future version of Streamlit. Keep at an eye out for updates on this page and the Streamlit roadmap.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-42", "text": "While the ability to configure columns has yet to be released, there are techniques you can use with Pandas today to render columns as checkboxes, selectboxes, and change the type of columns.\n\nBoolean columns (checkboxes)\n\nTo render columns as checkboxes and clickable checkboxes in st.dataframe and st.experimental_data_editor, respectively, set the type of the Pandas column as bool.\n\nHere\u2019s an example of creating a Pandas DataFrame with column A containing boolean values. When we display it using st.dataframe, the boolean values are rendered as checkboxes, where True and False values are checked and unchecked, respectively.\n\nimport pandas as pd\n\n# create a dataframe with a boolean column\ndf = pd.DataFrame({\"A\": [True, False, True, False]})\n\n# show the dataframe with checkboxes\nst.dataframe(df)\nCopy\n\nNotice you cannot change their values from the frontend. To let users check and uncheck values, we display the dataframe with st.experimental_data_editor instead:\n\nimport pandas as pd\n\n# create a dataframe with a boolean column\ndf = pd.DataFrame({\"A\": [True, False, True, False]})\n\n# show the data editor with checkboxes\nst.experimental_data_editor(df)\nCopy\nCategorical columns (selectboxes)\n\nTo render columns as selectboxes with st.experimental_data_editor, set the type of the Pandas column as category:\n\nimport pandas as pd\n\ndf = pd.DataFrame(\n {\"command\": [\"st.selectbox\", \"st.slider\", \"st.balloons\", \"st.time_input\"]}\n)\ndf[\"command\"] = df[\"command\"].astype(\"category\")\n\nedited_df = st.experimental_data_editor(df)\nCopy", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-43", "text": "edited_df = st.experimental_data_editor(df)\nCopy\n\nIn some cases, you may want users to select categories that aren\u2019t in the original Pandas DataFrame. Let\u2019s say we use df from above. Currently, the command column can take on four unique values. What should we do if we want users to see additional options such as st.button and st.radio?\n\nTo add additional categories to the selection, use pandas.Series.cat.add_categories:\n\nimport pandas as pd\n\ndf = pd.DataFrame(\n {\"command\": [\"st.selectbox\", \"st.slider\", \"st.balloons\", \"st.time_input\"]}\n)\ndf[\"command\"] = (\n df[\"command\"].astype(\"category\").cat.add_categories([\"st.button\", \"st.radio\"])\n)\n\nedited_df = st.experimental_data_editor(df)\nCopy\nChange column type\n\nTo change the type of a column, you can change the type of the underlying Pandas DataFrame column. E.g., say you have a column with only integers but want users to be able to add numbers with decimals. To do so, simply change the Pandas DataFrame column type to float, like so:\n\nimport pandas as pd\n\nimport streamlit as st\n\n# create a dataframe with an integer column\ndf = pd.DataFrame({\"A\": [1, 2, 3, 4]})\n\n# unable to add float values to the column\nedited_df = st.experimental_data_editor(df)\n\n# cast the column to float\ndf[\"A\"] = df[\"A\"].astype(\"float\")\n\n# able to add float values to the column\nedited_df = st.experimental_data_editor(df)\nCopy\n\nIn the first data editor instance, you cannot add decimal values to any entries. But after casting column A to type float, we\u2019re able to edit the values as floating point numbers:\n\nHandling large datasets", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-44", "text": "Handling large datasets\n\nst.dataframe and st.experimental_data_editor have been designed to theoretically handle tables with millions of rows thanks to their highly performant implementation using the glide-data-grid library and HTML canvas. However, the maximum amount of data that an app can realistically handle will depend on several other factors, including:\n\nThe maximum size of WebSocket messages: Streamlit's WebSocket messages are configurable via the server.maxMessageSize config option, which limits the amount of data that can be transferred via the WebSocket connection at once.\nThe server memory: The amount of data that your app can handle will also depend on the amount of memory available on your server. If the server's memory is exceeded, the app may become slow or unresponsive.\nThe user's browser memory: Since all the data needs to be transferred to the user's browser for rendering, the amount of memory available on the user's device can also affect the app's performance. If the browser's memory is exceeded, it may crash or become unresponsive.\n\nIn addition to these factors, a slow network connection can also significantly slow down apps that handle large datasets.\n\nWhen handling large datasets with more than 150,000 rows, Streamlit applies additional optimizations and disables column sorting. This can help to reduce the amount of data that needs to be processed at once and improve the app's performance.\n\nLimitations\n\nWhile Streamlit's data editing capabilities offer a lot of functionality, there are some limitations to be aware of:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-45", "text": "The editing functionalities are not yet optimized for mobile devices.\nEditing is enabled only for a limited set of types (e.g. string, numbers, boolean). We are actively working on supporting more types soon, such as date, time, and datetime.\nEditing of Pandas DataFrames only supports the following index types:\u00a0RangeIndex, (string)\u00a0Index,\u00a0Float64Index,\u00a0Int64Index, and\u00a0UInt64Index.\nThe column type is inferred from the underlying data and cannot be configured yet.\nSome actions like deleting rows or searching data can only be triggered via keyboard hotkeys.\n\nWe are working to fix the above limitations in future releases, so keep an eye out for updates.\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nAdd statefulness to apps\nNext:\nWidget semantics\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nDataframes - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-46", "text": "Streamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nStatus elements/\nst.progress\nst.progress\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\nDisplay a progress bar.\nFunction signature\n[source]\n\nst.progress(value, text=None)\n\nParameters\n\nvalue (int or float)\n\n0 <= value <= 100 for int\n\n0.0 <= value <= 1.0 for float\n\ntext (str or None)\n\nA message to display above the progress bar. The text can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.\n\nThis also supports:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-47", "text": "This also supports:\n\nEmoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.\nLaTeX expressions, by wrapping them in \"$\" or \"$$\" (the \"$$\" must be on their own lines). Supported LaTeX functions are listed at https://katex.org/docs/supported.html.\nColored text, using the syntax :color[text to be colored], where color needs to be replaced with any of the following supported colors: blue, green, orange, red, violet.\n\nUnsupported elements are not displayed. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\\. Not an ordered list.\n\nExample\n\nHere is an example of a progress bar increasing over time:\n\nimport streamlit as st\nimport time\n\nprogress_text = \"Operation in progress. Please wait.\"\nmy_bar = st.progress(0, text=progress_text)\n\nfor percent_complete in range(100):\n time.sleep(0.1)\n my_bar.progress(percent_complete + 1, text=progress_text)\nCopy\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nStatus elements\nNext:\nst.spinner\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.progress - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-48", "text": "Streamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nWrite and magic/\nst.write\nst.write\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\n\nWrite arguments to the app.\n\nThis is the Swiss Army knife of Streamlit commands: it does different things depending on what you throw at it. Unlike other Streamlit commands, write() has some unique properties:\n\nYou can pass in multiple arguments, all of which will be written.\nIts behavior depends on the input types as follows.\nIt returns None, so its \"slot\" in the App cannot be reused.\nFunction signature\n[source]\n\nst.write(*args, unsafe_allow_html=False, **kwargs)\n\nParameters\n\n*args (any)\n\nOne or many objects to print to the App.\n\nArguments are handled as follows:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-49", "text": "One or many objects to print to the App.\n\nArguments are handled as follows:\n\nwrite(string) : Prints the formatted Markdown string, with\nsupport for LaTeX expression, emoji shortcodes, and colored text. See docs for st.markdown for more.\nwrite(data_frame) : Displays the DataFrame as a table.\nwrite(error) : Prints an exception specially.\nwrite(func) : Displays information about a function.\nwrite(module) : Displays information about the module.\nwrite(dict) : Displays dict in an interactive widget.\nwrite(mpl_fig) : Displays a Matplotlib figure.\nwrite(altair) : Displays an Altair chart.\nwrite(keras) : Displays a Keras model.\nwrite(graphviz) : Displays a Graphviz graph.\nwrite(plotly_fig) : Displays a Plotly figure.\nwrite(bokeh_fig) : Displays a Bokeh figure.\nwrite(sympy_expr) : Prints SymPy expression using LaTeX.\nwrite(htmlable) : Prints _repr_html_() for the object if available.\nwrite(obj) : Prints str(obj) if otherwise unknown.\n\nunsafe_allow_html (bool)\n\nThis is a keyword-only argument that defaults to False.\n\nBy default, any HTML tags found in strings will be escaped and therefore treated as pure text. This behavior may be turned off by setting this argument to True.\n\nThat said, we strongly advise against it. It is hard to write secure HTML, so by using this argument you may be compromising your users' security. For more information, see:\n\nhttps://github.com/streamlit/streamlit/issues/152\n\nExample\n\nIts basic use case is to draw Markdown-formatted text, whenever the input is a string:\n\nimport streamlit as st\n\nst.write('Hello, *World!* :sunglasses:')\nCopy\n(view standalone Streamlit app)\n\nAs mentioned earlier, st.write() also accepts other data formats, such as numbers, data frames, styled data frames, and assorted objects:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-50", "text": "import streamlit as st\nimport pandas as pd\n\nst.write(1234)\nst.write(pd.DataFrame({\n 'first column': [1, 2, 3, 4],\n 'second column': [10, 20, 30, 40],\n}))\nCopy\n(view standalone Streamlit app)\n\nFinally, you can pass in multiple arguments to do things like:\n\nimport streamlit as st\n\nst.write('1 + 1 = ', 2)\nst.write('Below is a DataFrame:', data_frame, 'Above is a dataframe.')\nCopy\n(view standalone Streamlit app)\n\nOh, one more thing: st.write accepts chart objects too! For example:\n\nimport streamlit as st\nimport pandas as pd\nimport numpy as np\nimport altair as alt\n\ndf = pd.DataFrame(\n np.random.randn(200, 3),\n columns=['a', 'b', 'c'])\n\nc = alt.Chart(df).mark_circle().encode(\n x='a', y='b', size='c', color='c', tooltip=['a', 'b', 'c'])\n\nst.write(c)\nCopy\n(view standalone Streamlit app)\nFeatured video\n\nLearn what the st.write and magic commands are and how to use them.\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nWrite and magic\nNext:\nmagic\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.write - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nWrite and magic/\nmagic\nMagic", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-51", "text": "Knowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nWrite and magic/\nmagic\nMagic\n\nMagic commands are a feature in Streamlit that allows you to write almost anything (markdown, data, charts) without having to type an explicit command at all. Just put the thing you want to show on its own line of code, and it will appear in your app. Here's an example:\n\n# Draw a title and some text to the app:\n'''\n# This is the document title\n\nThis is some _markdown_.\n'''\n\nimport pandas as pd\ndf = pd.DataFrame({'col1': [1,2,3]})\ndf # \ud83d\udc48 Draw the dataframe\n\nx = 10\n'x', x # \ud83d\udc48 Draw the string 'x' and then the value of x\n\n# Also works with most supported chart types\nimport matplotlib.pyplot as plt\nimport numpy as np\n\narr = np.random.normal(1, 1, size=100)\nfig, ax = plt.subplots()\nax.hist(arr, bins=20)\n\nfig # \ud83d\udc48 Draw a Matplotlib chart\nCopy\nHow Magic works\n\nAny time Streamlit sees either a variable or literal value on its own line, it automatically writes that to your app using st.write (which you'll learn about later).\n\nAlso, magic is smart enough to ignore docstrings. That is, it ignores the strings at the top of files and functions.\n\nIf you prefer to call Streamlit commands more explicitly, you can always turn magic off in your ~/.streamlit/config.toml with the following setting:\n\n[runner]\nmagicEnabled = false\nCopy\npriority_high\nImportant\n\nRight now, Magic only works in the main Python app file, not in imported files. See GitHub issue #288 for a discussion of the issues.\n\nFeatured video\n\nLearn what the st.write and magic commands are and how to use them.\n\nWas this page helpful?", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-52", "text": "Was this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nst.write\nNext:\nText elements\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nMagic - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nText elements/\nst.markdown\nst.markdown\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\nDisplay string formatted as Markdown.\nFunction signature\n[source]\n\nst.markdown(body, unsafe_allow_html=False)\n\nParameters\n\nbody (str)\n\nThe string to display as Github-flavored Markdown. Syntax information can be found at: https://github.github.com/gfm.\n\nThis also supports:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-53", "text": "This also supports:\n\nEmoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.\nLaTeX expressions, by wrapping them in \"$\" or \"$$\" (the \"$$\" must be on their own lines). Supported LaTeX functions are listed at https://katex.org/docs/supported.html.\nColored text, using the syntax :color[text to be colored], where color needs to be replaced with any of the following supported colors: blue, green, orange, red, violet.\n\nunsafe_allow_html (bool)\n\nBy default, any HTML tags found in the body will be escaped and therefore treated as pure text. This behavior may be turned off by setting this argument to True.\n\nThat said, we strongly advise against it. It is hard to write secure HTML, so by using this argument you may be compromising your users' security. For more information, see:\n\nhttps://github.com/streamlit/streamlit/issues/152\n\nExamples\nimport streamlit as st\n\nst.markdown('Streamlit is **_really_ cool**.')\nst.markdown(\u201dThis text is :red[colored red], and this is **:blue[colored]** and bold.\u201d)\nst.markdown(\":green[$\\sqrt{x^2+y^2}=1$] is a Pythagorean identity. :pencil:\")\nCopy\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nText elements\nNext:\nst.title\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.markdown - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-54", "text": "dark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nText elements/\nst.code\nst.code\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\n\nDisplay a code block with optional syntax highlighting.\n\n(This is a convenience wrapper around st.markdown())\n\nFunction signature\n[source]\n\nst.code(body, language=\"python\")\n\nParameters\n\nbody (str)\n\nThe string to display as code.\n\nlanguage (str or None)\n\nThe language that the code is written in, for syntax highlighting. If None, the code will be unstyled. Defaults to \"python\".\n\nFor a list of available language values, see:\n\nhttps://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_PRISM.MD\n\nExample\nimport streamlit as st\n\ncode = '''def hello():\n print(\"Hello, Streamlit!\")'''\nst.code(code, language='python')\nCopy", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-55", "text": "Was this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nst.caption\nNext:\nst.text\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.code - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nInput widgets/\nst.button\nst.button\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\nDisplay a button widget.\nFunction signature\n[source]\n\nst.button(label, key=None, help=None, on_click=None, args=None, kwargs=None, *, type=\"secondary\", disabled=False, use_container_width=False)\n\nParameters\n\nlabel (str)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-56", "text": "Parameters\n\nlabel (str)\n\nA short label explaining to the user what this button is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, and Emojis.\n\nUnsupported elements are not displayed. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\\. Not an ordered list.\n\nkey (str or int)\n\nAn optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.\n\nhelp (str)\n\nAn optional tooltip that gets displayed when the button is hovered over.\n\non_click (callable)\n\nAn optional callback invoked when this button is clicked.\n\nargs (tuple)\n\nAn optional tuple of args to pass to the callback.\n\nkwargs (dict)\n\nAn optional dict of kwargs to pass to the callback.\n\ntype (\"secondary\" or \"primary\")\n\nAn optional string that specifies the button type. Can be \"primary\" for a button with additional emphasis or \"secondary\" for a normal button. This argument can only be supplied by keyword. Defaults to \"secondary\".\n\ndisabled (bool)\n\nAn optional boolean, which disables the button if set to True. The default is False. This argument can only be supplied by keyword.\n\nuse_container_width (bool)\n\nAn optional boolean, which makes the button stretch its width to match the parent container.\n\nReturns\n\n(bool)\n\nTrue if the button was clicked on the last run of the app, False otherwise.\n\nExample\nimport streamlit as st\n\nif st.button('Say hello'):\n st.write('Why hello there')\nelse:\n st.write('Goodbye')\nCopy\n(view standalone Streamlit app)\nFeatured videos\n\nCheck out our video on how to use one of Streamlit's core functions, the button!", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-57", "text": "Check out our video on how to use one of Streamlit's core functions, the button!\n\nIn the video below, we'll take it a step further and learn how to combine a button, checkbox and radio button!\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nInput widgets\nNext:\nst.experimental_data_editor\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.button - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nInput widgets/\nst.experimental_data_editor\npriority_high\nImportant\n\nThis is an experimental feature. Experimental features and their APIs may change or be removed at any time. To learn more, click here.\n\nstar\nTip\n\nThis page only contains information on the st.experimental_data_editor API. For a deeper dive into working with DataFrames and the data editor's capabilities, read Dataframes.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-58", "text": "st.experimental_data_editor\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\n\nDisplay a data editor widget.\n\nDisplay a data editor widget that allows you to edit DataFrames and many other data structures in a table-like UI.\n\nFunction signature\n[source]\n\nst.experimental_data_editor(data, *, width=None, height=None, use_container_width=False, num_rows=\"fixed\", disabled=False, key=None, on_change=None, args=None, kwargs=None)\n\nParameters\n\ndata (pandas.DataFrame, pandas.Styler, pandas.Index, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.DataFrame, list, set, tuple, dict, or None)\n\nThe data to edit in the data editor.\n\nwidth (int or None)\n\nDesired width of the data editor expressed in pixels. If None, the width will be automatically determined.\n\nheight (int or None)\n\nDesired height of the data editor expressed in pixels. If None, the height will be automatically determined.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-59", "text": "use_container_width (bool)\n\nIf True, set the data editor width to the width of the parent container. This takes precedence over the width argument. Defaults to False.\n\nnum_rows (\"fixed\" or \"dynamic\")\n\nSpecifies if the user can add and delete rows in the data editor. If \"fixed\", the user cannot add or delete rows. If \"dynamic\", the user can add and delete rows in the data editor, but column sorting is disabled. Defaults to \"fixed\".\n\ndisabled (bool)\n\nAn optional boolean which, if True, disables the data editor and prevents any edits. Defaults to False. This argument can only be supplied by keyword.\n\nkey (str)\n\nAn optional string to use as the unique key for this widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.\n\non_change (callable)\n\nAn optional callback invoked when this data_editor's value changes.\n\nargs (tuple)\n\nAn optional tuple of args to pass to the callback.\n\nkwargs (dict)\n\nAn optional dict of kwargs to pass to the callback.\n\nReturns\n\n(pd.DataFrame, pd.Styler, pyarrow.Table, np.ndarray, list, set, tuple, or dict.)\n\nThe edited data. The edited data is returned in its original data type if it corresponds to any of the supported return types. All other data types are returned as a pd.DataFrame.\n\nExamples\nimport streamlit as st\nimport pandas as pd\n\ndf = pd.DataFrame(\n [\n {\"command\": \"st.selectbox\", \"rating\": 4, \"is_widget\": True},\n {\"command\": \"st.balloons\", \"rating\": 5, \"is_widget\": False},\n {\"command\": \"st.time_input\", \"rating\": 3, \"is_widget\": True},\n ]\n)\nedited_df = st.experimental_data_editor(df)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-60", "text": "favorite_command = edited_df.loc[edited_df[\"rating\"].idxmax()][\"command\"]\nst.markdown(f\"Your favorite command is **{favorite_command}** \ud83c\udf88\")\nCopy\n(view standalone Streamlit app)\n\nYou can also allow the user to add and delete rows by setting num_rows to \"dynamic\":\n\nimport streamlit as st\nimport pandas as pd\n\ndf = pd.DataFrame(\n [\n {\"command\": \"st.selectbox\", \"rating\": 4, \"is_widget\": True},\n {\"command\": \"st.balloons\", \"rating\": 5, \"is_widget\": False},\n {\"command\": \"st.time_input\", \"rating\": 3, \"is_widget\": True},\n ]\n)\nedited_df = st.experimental_data_editor(df, num_rows=\"dynamic\")\n\nfavorite_command = edited_df.loc[edited_df[\"rating\"].idxmax()][\"command\"]\nst.markdown(f\"Your favorite command is **{favorite_command}** \ud83c\udf88\")\nCopy\n(view standalone Streamlit app)\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nst.button\nNext:\nst.download_button\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.experimental_data_editor - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-61", "text": "Streamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nInput widgets/\nst.download_button\nst.download_button\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\n\nDisplay a download button widget.\n\nThis is useful when you would like to provide a way for your users to download a file directly from your app.\n\nNote that the data to be downloaded is stored in-memory while the user is connected, so it's a good idea to keep file sizes under a couple hundred megabytes to conserve memory.\n\nFunction signature\n[source]\n\nst.download_button(label, data, file_name=None, mime=None, key=None, help=None, on_click=None, args=None, kwargs=None, *, disabled=False, use_container_width=False)\n\nParameters\n\nlabel (str)\n\nA short label explaining to the user what this button is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, and Emojis.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-62", "text": "Unsupported elements are not displayed. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\\. Not an ordered list.\n\ndata (str or bytes or file)\n\nThe contents of the file to be downloaded. See example below for caching techniques to avoid recomputing this data unnecessarily.\n\nfile_name (str)\n\nAn optional string to use as the name of the file to be downloaded, such as 'my_file.csv'. If not specified, the name will be automatically generated.\n\nmime (str or None)\n\nThe MIME type of the data. If None, defaults to \"text/plain\" (if data is of type str or is a textual file) or \"application/octet-stream\" (if data is of type bytes or is a binary file).\n\nkey (str or int)\n\nAn optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.\n\nhelp (str)\n\nAn optional tooltip that gets displayed when the button is hovered over.\n\non_click (callable)\n\nAn optional callback invoked when this button is clicked.\n\nargs (tuple)\n\nAn optional tuple of args to pass to the callback.\n\nkwargs (dict)\n\nAn optional dict of kwargs to pass to the callback.\n\ndisabled (bool)\n\nAn optional boolean, which disables the download button if set to True. The default is False. This argument can only be supplied by keyword.\n\nuse_container_width (bool)\n\nAn optional boolean, which makes the button stretch its width to match the parent container.\n\nReturns\n\n(bool)\n\nTrue if the button was clicked on the last run of the app, False otherwise.\n\nExamples\n\nDownload a large DataFrame as a CSV:\n\nimport streamlit as st", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-63", "text": "Examples\n\nDownload a large DataFrame as a CSV:\n\nimport streamlit as st\n\n@st.cache\ndef convert_df(df):\n # IMPORTANT: Cache the conversion to prevent computation on every rerun\n return df.to_csv().encode('utf-8')\n\ncsv = convert_df(my_large_df)\n\nst.download_button(\n label=\"Download data as CSV\",\n data=csv,\n file_name='large_df.csv',\n mime='text/csv',\n)\nCopy\n\nDownload a string as a file:\n\nimport streamlit as st\n\ntext_contents = '''This is some text'''\nst.download_button('Download some text', text_contents)\nCopy\n\nDownload a binary file:\n\nimport streamlit as st\n\nbinary_contents = b'example content'\n# Defaults to 'application/octet-stream'\nst.download_button('Download binary file', binary_contents)\nCopy\n\nDownload an image:\n\nimport streamlit as st\n\nwith open(\"flower.png\", \"rb\") as file:\n btn = st.download_button(\n label=\"Download image\",\n data=file,\n file_name=\"flower.png\",\n mime=\"image/png\"\n )\nCopy\n(view standalone Streamlit app)\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nst.experimental_data_editor\nNext:\nst.checkbox\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.download_button - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-64", "text": "Streamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nInput widgets/\nst.text_input\nst.text_input\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\nDisplay a single-line text input widget.\nFunction signature\n[source]\n\nst.text_input(label, value=\"\", max_chars=None, key=None, type=\"default\", help=None, autocomplete=None, on_change=None, args=None, kwargs=None, *, placeholder=None, disabled=False, label_visibility=\"visible\")\n\nParameters\n\nlabel (str)\n\nA short label explaining to the user what this input is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.\n\nThis also supports:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-65", "text": "This also supports:\n\nEmoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.\nLaTeX expressions, by wrapping them in \"$\" or \"$$\" (the \"$$\" must be on their own lines). Supported LaTeX functions are listed at https://katex.org/docs/supported.html.\nColored text, using the syntax :color[text to be colored], where color needs to be replaced with any of the following supported colors: blue, green, orange, red, violet.\n\nUnsupported elements are not displayed. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\\. Not an ordered list.\n\nFor accessibility reasons, you should never set an empty label (label=\"\") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.\n\nvalue (object)\n\nThe text value of this widget when it first renders. This will be cast to str internally.\n\nmax_chars (int or None)\n\nMax number of characters allowed in text input.\n\nkey (str or int)\n\nAn optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.\n\ntype (str)\n\nThe type of the text input. This can be either \"default\" (for a regular text input), or \"password\" (for a text input that masks the user's typed value). Defaults to \"default\".\n\nhelp (str)\n\nAn optional tooltip that gets displayed next to the input.\n\nautocomplete (str)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-66", "text": "An optional tooltip that gets displayed next to the input.\n\nautocomplete (str)\n\nAn optional value that will be passed to the <input> element's autocomplete property. If unspecified, this value will be set to \"new-password\" for \"password\" inputs, and the empty string for \"default\" inputs. For more details, see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete\n\non_change (callable)\n\nAn optional callback invoked when this text_input's value changes.\n\nargs (tuple)\n\nAn optional tuple of args to pass to the callback.\n\nkwargs (dict)\n\nAn optional dict of kwargs to pass to the callback.\n\nplaceholder (str or None)\n\nAn optional string displayed when the text input is empty. If None, no text is displayed. This argument can only be supplied by keyword.\n\ndisabled (bool)\n\nAn optional boolean, which disables the text input if set to True. The default is False. This argument can only be supplied by keyword.\n\nlabel_visibility (\"visible\" or \"hidden\" or \"collapsed\")\n\nThe visibility of the label. If \"hidden\", the label doesn't show but there is still empty space for it above the widget (equivalent to label=\"\"). If \"collapsed\", both the label and the space are removed. Default is \"visible\". This argument can only be supplied by keyword.\n\nReturns\n\n(str)\n\nThe current value of the text input widget.\n\nExample\nimport streamlit as st\n\ntitle = st.text_input('Movie title', 'Life of Brian')\nst.write('The current movie title is', title)\nCopy\n(view standalone Streamlit app)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-67", "text": "Text input widgets can customize how to hide their labels with the label_visibility parameter. If \"hidden\", the label doesn\u2019t show but there is still empty space for it above the widget (equivalent to label=\"\"). If \"collapsed\", both the label and the space are removed. Default is \"visible\". Text input widgets can also be disabled with the disabled parameter, and can display an optional placeholder text when the text input is empty using the placeholder parameter:\n\nimport streamlit as st\n\n# Store the initial value of widgets in session state\nif \"visibility\" not in st.session_state:\n st.session_state.visibility = \"visible\"\n st.session_state.disabled = False\n\ncol1, col2 = st.columns(2)\n\nwith col1:\n st.checkbox(\"Disable text input widget\", key=\"disabled\")\n st.radio(\n \"Set text input label visibility \ud83d\udc49\",\n key=\"visibility\",\n options=[\"visible\", \"hidden\", \"collapsed\"],\n )\n st.text_input(\n \"Placeholder for the other text input widget\",\n \"This is a placeholder\",\n key=\"placeholder\",\n )\n\nwith col2:\n text_input = st.text_input(\n \"Enter some text \ud83d\udc47\",\n label_visibility=st.session_state.visibility,\n disabled=st.session_state.disabled,\n placeholder=st.session_state.placeholder,\n )\n\n if text_input:\n st.write(\"You entered: \", text_input)\nCopy\n(view standalone Streamlit app)\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nst.select_slider\nNext:\nst.number_input\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.text_input - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-68", "text": "Search\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nInput widgets/\nst.file_uploader\nst.file_uploader\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\n\nDisplay a file uploader widget.\n\nBy default, uploaded files are limited to 200MB. You can configure this using the server.maxUploadSize config option. For more info on how to set config options, see https://docs.streamlit.io/library/advanced-features/configuration#set-configuration-options\n\nFunction signature\n[source]\n\nst.file_uploader(label, type=None, accept_multiple_files=False, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility=\"visible\")\n\nParameters\n\nlabel (str)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-69", "text": "Parameters\n\nlabel (str)\n\nA short label explaining to the user what this file uploader is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.\n\nThis also supports:\n\nEmoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.\nLaTeX expressions, by wrapping them in \"$\" or \"$$\" (the \"$$\" must be on their own lines). Supported LaTeX functions are listed at https://katex.org/docs/supported.html.\nColored text, using the syntax :color[text to be colored], where color needs to be replaced with any of the following supported colors: blue, green, orange, red, violet.\n\nUnsupported elements are not displayed. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\\. Not an ordered list.\n\nFor accessibility reasons, you should never set an empty label (label=\"\") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.\n\ntype (str or list of str or None)\n\nArray of allowed extensions. ['png', 'jpg'] The default is None, which means all extensions are allowed.\n\naccept_multiple_files (bool)\n\nIf True, allows the user to upload multiple files at the same time, in which case the return value will be a list of files. Default: False\n\nkey (str or int)\n\nAn optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.\n\nhelp (str)\n\nA tooltip that gets displayed next to the file uploader.\n\non_change (callable)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-70", "text": "A tooltip that gets displayed next to the file uploader.\n\non_change (callable)\n\nAn optional callback invoked when this file_uploader's value changes.\n\nargs (tuple)\n\nAn optional tuple of args to pass to the callback.\n\nkwargs (dict)\n\nAn optional dict of kwargs to pass to the callback.\n\ndisabled (bool)\n\nAn optional boolean, which disables the file uploader if set to True. The default is False. This argument can only be supplied by keyword.\n\nlabel_visibility (\"visible\" or \"hidden\" or \"collapsed\")\n\nThe visibility of the label. If \"hidden\", the label doesn't show but there is still empty space for it above the widget (equivalent to label=\"\"). If \"collapsed\", both the label and the space are removed. Default is \"visible\". This argument can only be supplied by keyword.\n\nReturns\n\n(None or UploadedFile or list of UploadedFile)\n\nIf accept_multiple_files is False, returns either None or an UploadedFile object.\nIf accept_multiple_files is True, returns a list with the uploaded files as UploadedFile objects. If no files were uploaded, returns an empty list.\n\nThe UploadedFile class is a subclass of BytesIO, and therefore it is \"file-like\". This means you can pass them anywhere where a file is expected.\n\nExamples\n\nInsert a file uploader that accepts a single file at a time:\n\nimport streamlit as st\nimport pandas as pd\nfrom io import StringIO\n\nuploaded_file = st.file_uploader(\"Choose a file\")\nif uploaded_file is not None:\n # To read file as bytes:\n bytes_data = uploaded_file.getvalue()\n st.write(bytes_data)\n\n # To convert to a string based IO:\n stringio = StringIO(uploaded_file.getvalue().decode(\"utf-8\"))\n st.write(stringio)\n\n # To read file as string:\n string_data = stringio.read()\n st.write(string_data)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-71", "text": "# Can be used wherever a \"file-like\" object is accepted:\n dataframe = pd.read_csv(uploaded_file)\n st.write(dataframe)\nCopy\n\nInsert a file uploader that accepts multiple files at a time:\n\nimport streamlit as st\n\nuploaded_files = st.file_uploader(\"Choose a CSV file\", accept_multiple_files=True)\nfor uploaded_file in uploaded_files:\n bytes_data = uploaded_file.read()\n st.write(\"filename:\", uploaded_file.name)\n st.write(bytes_data)\nCopy\n(view standalone Streamlit app)\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nst.time_input\nNext:\nst.camera_input\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.file_uploader - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-72", "text": "Streamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAPI reference/\nInput widgets/\nst.selectbox\nst.selectbox\nStreamlit Version\nv1.20.0\nv1.19.0\nv1.18.0\nv1.17.0\nv1.16.0\nv1.15.0\nv1.14.0\nv1.13.0\nv1.12.0\nv1.11.0\nv1.10.0\nv1.9.0\nv1.8.0\nv1.7.0\nv1.6.0\nv1.5.0\nv1.4.0\nv1.3.0\nv1.2.0\nv1.1.0\nv1.0.0\nv0.89.0\nv0.88.0\nv0.87.0\nv0.86.0\nv0.85.0\nv0.84.0\nv0.83.0\nDisplay a select widget.\nFunction signature\n[source]\n\nst.selectbox(label, options, index=0, format_func=special_internal_function, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility=\"visible\")\n\nParameters\n\nlabel (str)\n\nA short label explaining to the user what this select widget is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.\n\nThis also supports:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-73", "text": "This also supports:\n\nEmoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.\nLaTeX expressions, by wrapping them in \"$\" or \"$$\" (the \"$$\" must be on their own lines). Supported LaTeX functions are listed at https://katex.org/docs/supported.html.\nColored text, using the syntax :color[text to be colored], where color needs to be replaced with any of the following supported colors: blue, green, orange, red, violet.\n\nUnsupported elements are not displayed. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\\. Not an ordered list.\n\nFor accessibility reasons, you should never set an empty label (label=\"\") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.\n\noptions (Sequence, numpy.ndarray, pandas.Series, pandas.DataFrame, or pandas.Index)\n\nLabels for the select options. This will be cast to str internally by default. For pandas.DataFrame, the first column is selected.\n\nindex (int)\n\nThe index of the preselected option on first render.\n\nformat_func (function)\n\nFunction to modify the display of the labels. It receives the option as an argument and its output will be cast to str.\n\nkey (str or int)\n\nAn optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.\n\nhelp (str)\n\nAn optional tooltip that gets displayed next to the selectbox.\n\non_change (callable)\n\nAn optional callback invoked when this selectbox's value changes.\n\nargs (tuple)\n\nAn optional tuple of args to pass to the callback.\n\nkwargs (dict)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-74", "text": "An optional tuple of args to pass to the callback.\n\nkwargs (dict)\n\nAn optional dict of kwargs to pass to the callback.\n\ndisabled (bool)\n\nAn optional boolean, which disables the selectbox if set to True. The default is False. This argument can only be supplied by keyword.\n\nlabel_visibility (\"visible\" or \"hidden\" or \"collapsed\")\n\nThe visibility of the label. If \"hidden\", the label doesn't show but there is still empty space for it above the widget (equivalent to label=\"\"). If \"collapsed\", both the label and the space are removed. Default is \"visible\". This argument can only be supplied by keyword.\n\nReturns\n\n(any)\n\nThe selected option\n\nExample\nimport streamlit as st\n\noption = st.selectbox(\n 'How would you like to be contacted?',\n ('Email', 'Home phone', 'Mobile phone'))\n\nst.write('You selected:', option)\nCopy\n(view standalone Streamlit app)\n\n\n\nSelect widgets can customize how to hide their labels with the label_visibility parameter. If \"hidden\", the label doesn\u2019t show but there is still empty space for it above the widget (equivalent to label=\"\"). If \"collapsed\", both the label and the space are removed. Default is \"visible\". Select widgets can also be disabled with the disabled parameter:\n\nimport streamlit as st\n\n# Store the initial value of widgets in session state\nif \"visibility\" not in st.session_state:\n st.session_state.visibility = \"visible\"\n st.session_state.disabled = False\n\ncol1, col2 = st.columns(2)\n\nwith col1:\n st.checkbox(\"Disable selectbox widget\", key=\"disabled\")\n st.radio(\n \"Set selectbox label visibility \ud83d\udc49\",\n key=\"visibility\",\n options=[\"visible\", \"hidden\", \"collapsed\"],\n )", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-75", "text": "with col2:\n option = st.selectbox(\n \"How would you like to be contacted?\",\n (\"Email\", \"Home phone\", \"Mobile phone\"),\n label_visibility=st.session_state.visibility,\n disabled=st.session_state.disabled,\n )\nCopy\n(view standalone Streamlit app)\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nst.radio\nNext:\nst.multiselect\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nst.selectbox - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAdvanced features/\nConfiguration\nConfiguration\n\nStreamlit provides four different ways to set configuration options. This list is in reverse order of precedence, i.e. command line flags take precedence over environment variables when the same configuration option is provided multiple times.\n\npush_pin\nNote\n\nIf changes to .streamlit/config.toml are made while the app is running, the server needs to be restarted for changes to be reflected in the app.\n\nIn a global config file at ~/.streamlit/config.toml for macOS/Linux or %userprofile%/.streamlit/config.toml for Windows:\n\n[server]\nport = 80\nCopy\n\nIn a per-project config file at $CWD/.streamlit/config.toml, where $CWD is the folder you're running Streamlit from.\n\nThrough STREAMLIT_* environment variables, such as:\n\nexport STREAMLIT_SERVER_PORT=80\nexport STREAMLIT_SERVER_COOKIE_SECRET=dontforgottochangeme\nCopy\n\nAs flags on the command line when running streamlit run:", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-76", "text": "As flags on the command line when running streamlit run:\n\nstreamlit run your_script.py --server.port 80\nCopy\nstar\nTip\n\nTo set configuration options on Streamlit Community Cloud, read Optionally, add a configuration file in the Streamlit Community Cloud docs.\n\nTelemetry\n\nAs mentioned during the installation process, Streamlit collects usage statistics. You can find out more by reading our Privacy Notice, but the high-level summary is that although we collect telemetry data we cannot see and do not store information contained in Streamlit apps.\n\nIf you'd like to opt out of usage statistics, add the following to your config file:\n\n[browser]\ngatherUsageStats = false\nCopy\nTheming\n\nYou can change the base colors of your app using the [theme] section of the configuration system. To learn more, see Theming.\n\nView all configuration options\n\nAs described in Command-line options, you can view all available configuration option using:\n\nstreamlit config show\nCopy\n\nThe command above will print something like this:\n\n# Streamlit version: 1.20.0\n\n[global]\n\n# By default, Streamlit checks if the Python watchdog module is available and, if not, prints a warning asking for you to install it. The watchdog module is not required, but highly recommended. It improves Streamlit's ability to detect changes to files in your filesystem.\n# If you'd like to turn off this warning, set this to True.\n# Default: false\ndisableWatchdogWarning = false\n\n# If True, will show a warning when you run a Streamlit-enabled script via \"python my_script.py\".\n# Default: true\nshowWarningOnDirectExecution = true", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-77", "text": "# DataFrame serialization.\n# Acceptable values: - 'legacy': Serialize DataFrames using Streamlit's custom format. Slow but battle-tested. - 'arrow': Serialize DataFrames using Apache Arrow. Much faster and versatile.\n# Default: \"arrow\"\ndataFrameSerialization = \"arrow\"\n\n\n[logger]\n\n# Level of logging: 'error', 'warning', 'info', or 'debug'.\n# Default: 'info'\nlevel = \"info\"\n\n# String format for logging messages. If logger.datetimeFormat is set, logger messages will default to `%(asctime)s.%(msecs)03d %(message)s`. See [Python's documentation](https://docs.python.org/2.6/library/logging.html#formatter-objects) for available attributes.\n# Default: \"%(asctime)s %(message)s\"\nmessageFormat = \"%(asctime)s %(message)s\"\n\n\n[client]\n\n# Whether to enable st.cache.\n# Default: true\ncaching = true\n\n# If false, makes your Streamlit script not draw to a Streamlit app.\n# Default: true\ndisplayEnabled = true\n\n# Controls whether uncaught app exceptions are displayed in the browser. By default, this is set to True and Streamlit displays app exceptions and associated tracebacks in the browser.\n# If set to False, an exception will result in a generic message being shown in the browser, and exceptions and tracebacks will be printed to the console only.\n# Default: true\nshowErrorDetails = true\n\n\n[runner]\n\n# Allows you to type a variable or string by itself in a single line of Python code to write it to the app.\n# Default: true\nmagicEnabled = true\n\n# Install a Python tracer to allow you to stop or pause your script at any point and introspect it. As a side-effect, this slows down your script's execution.\n# Default: false\ninstallTracer = false", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-78", "text": "# Sets the MPLBACKEND environment variable to Agg inside Streamlit to prevent Python crashing.\n# Default: true\nfixMatplotlib = true\n\n# Run the Python Garbage Collector after each script execution. This can help avoid excess memory use in Streamlit apps, but could introduce delay in rerunning the app script for high-memory-use applications.\n# Default: true\npostScriptGC = true\n\n# Handle script rerun requests immediately, rather than waiting for script execution to reach a yield point. This makes Streamlit much more responsive to user interaction, but it can lead to race conditions in apps that mutate session_state data outside of explicit session_state assignment statements.\n# Default: true\nfastReruns = true\n\n\n[server]\n\n# List of folders that should not be watched for changes. This impacts both \"Run on Save\" and @st.cache.\n# Relative paths will be taken as relative to the current working directory.\n# Example: ['/home/user1/env', 'relative/path/to/folder']\n# Default: []\nfolderWatchBlacklist = []\n\n# Change the type of file watcher used by Streamlit, or turn it off completely.\n# Allowed values: * \"auto\" : Streamlit will attempt to use the watchdog module, and falls back to polling if watchdog is not available. * \"watchdog\" : Force Streamlit to use the watchdog module. * \"poll\" : Force Streamlit to always use polling. * \"none\" : Streamlit will not watch files.\n# Default: \"auto\"\nfileWatcherType = \"auto\"\n\n# Symmetric key used to produce signed cookies. If deploying on multiple replicas, this should be set to the same value across all replicas to ensure they all share the same secret.\n# Default: randomly generated secret key.\ncookieSecret =", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-79", "text": "# If false, will attempt to open a browser window on start.\n# Default: false unless (1) we are on a Linux box where DISPLAY is unset, or (2) we are running in the Streamlit Atom plugin.\nheadless = false\n\n# Automatically rerun script when the file is modified on disk.\n# Default: false\nrunOnSave = false\n\n# The address where the server will listen for client and browser connections. Use this if you want to bind the server to a specific address. If set, the server will only be accessible from this address, and not from any aliases (like localhost).\n# Default: (unset)\n# address =\n\n# The port where the server will listen for browser connections.\n# Default: 8501\nport = 8501\n\n# The base path for the URL where Streamlit should be served from.\n# Default: \"\"\nbaseUrlPath = \"\"\n\n# Enables support for Cross-Origin Request Sharing (CORS) protection, for added security.\n# Due to conflicts between CORS and XSRF, if `server.enableXsrfProtection` is on and `server.enableCORS` is off at the same time, we will prioritize `server.enableXsrfProtection`.\n# Default: true\nenableCORS = true\n\n# Enables support for Cross-Site Request Forgery (XSRF) protection, for added security.\n# Due to conflicts between CORS and XSRF, if `server.enableXsrfProtection` is on and `server.enableCORS` is off at the same time, we will prioritize `server.enableXsrfProtection`.\n# Default: true\nenableXsrfProtection = true\n\n# Max size, in megabytes, for files uploaded with the file_uploader.\n# Default: 200\nmaxUploadSize = 200", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-80", "text": "# Max size, in megabytes, of messages that can be sent via the WebSocket connection.\n# Default: 200\nmaxMessageSize = 200\n\n# Enables support for websocket compression.\n# Default: false\nenableWebsocketCompression = false\n\n# Enable serving files from a `static` directory in the running app's directory.\n# Default: false\nenableStaticServing = false\n\n# Server certificate file for connecting via HTTPS. Must be set at the same time as \"server.sslKeyFile\".\n# ['DO NOT USE THIS OPTION IN A PRODUCTION ENVIRONMENT. It has not gone through security audits or performance tests. For the production environment, we recommend performing SSL termination by the load balancer or the reverse proxy.']\n# sslCertFile =\n\n# Cryptographic key file for connecting via HTTPS. Must be set at the same time as \"server.sslCertFile\".\n# ['DO NOT USE THIS OPTION IN A PRODUCTION ENVIRONMENT. It has not gone through security audits or performance tests. For the production environment, we recommend performing SSL termination by the load balancer or the reverse proxy.']\n# sslKeyFile =\n\n[browser]\n\n# Internet address where users should point their browsers in order to connect to the app. Can be IP address or DNS name and path.\n# This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser\n# Default: 'localhost'\nserverAddress = \"localhost\"\n\n# Whether to send usage statistics to Streamlit.\n# Default: true\ngatherUsageStats = true\n\n# Port where users should point their browsers in order to connect to the app.\n# This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser\n# Default: whatever value is set in server.port.\nserverPort = 8501\n\n\n[mapbox]", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-81", "text": "[mapbox]\n\n# Configure Streamlit to use a custom Mapbox token for elements like st.pydeck_chart and st.map. To get a token for yourself, create an account at https://mapbox.com. It's free (for moderate usage levels)!\n# Default: \"\"\ntoken = \"\"\n\n\n[deprecation]\n\n# Set to false to disable the deprecation warning for the file uploader encoding.\n# Default: true\nshowfileUploaderEncoding = true\n\n# Set to false to disable the deprecation warning for using the global pyplot instance.\n# Default: true\nshowPyplotGlobalUse = true\n\n\n[theme]\n\n# The preset Streamlit theme that your custom theme inherits from. One of \"light\" or \"dark\".\n# base =\n\n# Primary accent color for interactive elements.\n# primaryColor =\n\n# Background color for the main content area.\n# backgroundColor =\n\n# Background color used for the sidebar and most interactive widgets.\n# secondaryBackgroundColor =\n\n# Color used for almost all text.\n# textColor =\n\n# Font family for all text in the app, except code blocks. One of \"sans serif\", \"serif\", or \"monospace\".\n# font =\nCopy\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nCommand-line options\nNext:\nTheming\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nConfiguration - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAdvanced features/\nTheming\nTheming", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-82", "text": "school\n\nKnowledge base\n\nHome/\nStreamlit library/\nAdvanced features/\nTheming\nTheming\n\nIn this guide, we provide examples of how Streamlit page elements are affected by the various theme config options. For a more high-level overview of Streamlit themes, see the Themes section of the main concepts documentation.\n\nStreamlit themes are defined using regular config options: a theme can be set via command line flag when starting your app using streamlit run or by defining it in the [theme] section of a .streamlit/config.toml file. For more information on setting config options, please refer to the Streamlit configuration documentation.\n\nThe following config options show the default Streamlit Light theme recreated in the [theme] section of a .streamlit/config.toml file.\n\n[theme]\nprimaryColor=\"#F63366\"\nbackgroundColor=\"#FFFFFF\"\nsecondaryBackgroundColor=\"#F0F2F6\"\ntextColor=\"#262730\"\nfont=\"sans serif\"\nCopy\n\nLet's go through each of these options, providing screenshots to demonstrate what parts of a Streamlit app they affect where needed.\n\nprimaryColor\n\nprimaryColor defines the accent color most often used throughout a Streamlit app. A few examples of Streamlit widgets that use primaryColor include st.checkbox, st.slider, and st.text_input (when focused).\n\nstar\nTip\n\nAny CSS color can be used as the value for primaryColor and the other color options below. This means that theme colors can be specified in hex or with browser-supported color names like \"green\", \"yellow\", and \"chartreuse\". They can even be defined in the RGB and HSL formats!\n\nbackgroundColor\n\nDefines the background color used in the main content area of your app.\n\nsecondaryBackgroundColor\n\nThis color is used where a second background color is needed for added contrast. Most notably, it is the sidebar's background color. It is also used as the background color for most interactive widgets.\n\ntextColor", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-83", "text": "textColor\n\nThis option controls the text color for most of your Streamlit app.\n\nfont\n\nSelects the font used in your Streamlit app. Valid values are \"sans serif\", \"serif\", and \"monospace\". This option defaults to \"sans serif\" if unset or invalid.\n\nNote that code blocks are always rendered using the monospace font regardless of the font selected here.\n\nbase\n\nAn easy way to define custom themes that make small changes to one of the preset Streamlit themes is to use the base option. Using base, the Streamlit Light theme can be recreated as a custom theme by writing the following:\n\n[theme]\nbase=\"light\"\nCopy\n\nThe base option allows you to specify a preset Streamlit theme that your custom theme inherits from. Any theme config options not defined in your theme settings have their values set to those of the base theme. Valid values for base are \"light\" and \"dark\".\n\nFor example, the following theme config defines a custom theme nearly identical to the Streamlit Dark theme, but with a new primaryColor.\n\n[theme]\nbase=\"dark\"\nprimaryColor=\"purple\"\nCopy\n\nIf base itself is omitted, it defaults to \"light\", so you can define a custom theme that changes the font of the Streamlit Light theme to serif with the following config\n\n[theme]\nfont=\"serif\"\nCopy\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nConfiguration\nNext:\nCaching\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nTheming - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-84", "text": "Streamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit library/\nAdvanced features/\nWidget semantics\nAdvanced notes on widget behavior\n\nWidgets are magical and often work how you want. But they can have surprising behavior in some situations. Here is a high-level, abstract description of widget behavior, including some common edge-cases:\n\nIf you call a widget function before the widget state exists, the widget state defaults to a value. This value depends on the widget and its arguments.\nA widget function call returns the current widget state value. The return value is a simple Python type, and the exact type depends on the widget and its arguments.\nWidget states depend on a particular session (browser connection). The actions of one user do not affect the widgets of any other user.\nA widget's identity depends on the arguments passed to the widget function. If those change, the call will create a new widget (with a default value, per 1).\nIf you don't call a widget function in a script run, we neither store the widget state nor render the widget. If you call a widget function with the same arguments later, Streamlit treats it as a new widget.\n\n4 and 5 are the most likely to be surprising and may pose a problem for some application designs. When you want to persist widget state for recreating a widget, use Session State to work around 5.\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nDataframes\nNext:\nPre-release features\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nWidget semantics - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-85", "text": "Streamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit Community Cloud/\nGet started/\nDeploy an app/\nApp dependencies\nApp dependencies\n\nThe main reason that apps fail to build properly is because Streamlit Community Cloud can't find your dependencies! So make sure you:\n\nAdd a\u00a0requirements file\u00a0for Python dependencies.\n(optional) Add a\u00a0packages.txt\u00a0file to manage any external dependencies (i.e Linux dependencies outside Python environment).\npush_pin\nNote\n\nPython requirements files should be placed either in the root of your repository or in the same directory as your Streamlit app.\n\nAdd Python dependencies\n\nStreamlit looks at your requirements file's filename to determine which Python dependency manager to use in the order below. Streamlit will stop and install the first requirements file found.\n\nFilename\tDependency Manager\tDocumentation\nPipfile\tpipenv\tdocs\nenvironment.yml\tconda\tdocs\nrequirements.txt\tpip\tdocs\npyproject.toml\tpoetry\tdocs\npush_pin\nNote\n\nOnly include packages in your requirements file that are not distributed with a standard Python installation. If any of the modules from base Python are included in the requirements file, you will get an error when you try to deploy. Additionally, we recommend that you use the latest version of Streamlit to ensure full Streamlit Community Cloud functionality.\n\npriority_high\nWarning\n\nYou should only use one requirements file for your app. If you include more than one (e.g. requirements.txt and Pipfile). Streamlit will first look in the directory of your Streamlit app; however, if no requirements file is found, Streamlit will then look at the root of the repo.\n\napt-get dependencies\n\nIf packages.txt exists in the root directory of your repository we automatically detect it, parse it, and install the listed packages as described below. You can read more about apt-get in their docs.", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-86", "text": "Add apt-get dependencies to\u00a0packages.txt, one package name per line. For example:\n\nfreeglut3-dev\nlibgtk2.0-dev\nCopy\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nDeploy an app\nNext:\nConnect to data sources\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nApp dependencies - Streamlit Docssearch\n\nSearch\n\n\u2318K\n\ndark_mode\nlight_mode\ndescription\n\nStreamlit library\n\ncloud\n\nStreamlit Community Cloud\n\nschool\n\nKnowledge base\n\nHome/\nStreamlit Community Cloud/\nGet started/\nDeploy an app/\nConnect to data sources/\nSecrets management\nSecrets management\nIntroduction\n\nIt's generally considered bad practice to store unencrypted secrets in a git repository. If your application needs access to sensitive credentials the recommended solution is to store those credentials in a file that is not committed to the repository and to pass them as environment variables.\n\nSecrets Management allows you to store secrets securely and access them in your Streamlit app as environment variables.\n\nHow to use Secrets Management\nDeploy an app and set up secrets\n\nGo to http://share.streamlit.io/ and click \"New app\" to deploy a new app with secrets.\n\nClick \"Advanced settings...\"\n\nYou will see a modal appear with an input box for your secrets.\n\nProvide your secrets in the \"Secrets\" field using TOML format. For example:\n\n# Everything in this section will be available as an environment variable\ndb_username = \"Jane\"\ndb_password = \"12345qwerty\"", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-87", "text": "# You can also add other sections if you like.\n# The contents of sections as shown below will not become environment variables,\n# but they'll be easily accessible from within Streamlit anyway as we show\n# later in this doc.\n[my_cool_secrets]\nthings_i_like = [\"Streamlit\", \"Python\"]\nCopy\nUse secrets in your app\n\nAccess your secrets as environment variables or by querying the st.secrets dict. For example, if you enter the secrets from the section above, the code below shows you how you can access them within your Streamlit app.\n\nimport streamlit as st\n\n# Everything is accessible via the st.secrets dict:\n\nst.write(\"DB username:\", st.secrets[\"db_username\"])\nst.write(\"DB password:\", st.secrets[\"db_password\"])\nst.write(\"My cool secrets:\", st.secrets[\"my_cool_secrets\"][\"things_i_like\"])\n\n# And the root-level secrets are also accessible as environment variables:\n\nimport os\n\nst.write(\n \"Has environment variables been set:\",\n os.environ[\"db_username\"] == st.secrets[\"db_username\"],\n)\nCopy\nstar\nTip\n\nYou can access st.secrets via attribute notation (e.g. st.secrets.key), in addition to key notation (e.g. st.secrets[\"key\"])\u2014like st.session_state.\n\nYou can even use TOML sections to compactly pass multiple secrets as a single attribute.\n\nConsider the following secrets:\n\n[db_credentials]\nusername = \"my_username\"\npassword = \"my_password\"\nCopy\n\nRather than passing each secret as attributes in a function, you can more compactly pass the section to achieve the same result. See the notional code below which uses the secrets above:\n\n# Verbose version\nmy_db.connect(username=st.secrets.db_credentials.username, password=st.secrets.db_credentials.password)", "source": "streamlit-docs.txt"}
{"id": "e4409cd96e13-88", "text": "# Far more compact version!\nmy_db.connect(**st.secrets.db_credentials)\nCopy\nEdit your app's secrets\nGo to https://share.streamlit.io/\nOpen the menu for your app, and click \"Settings\". \nYou will see a modal appear. Click on the \"Secrets\" section and edit your secrets. \nAfter you edit your secrets, click \"Save\". It might take a minute for the update to be propagated to your app, but the new values will be reflected when the app re-runs.\nDevelop locally with secrets\n\nWhen developing your app locally, add a file called secrets.toml in a folder called .streamlit at the root of your app repo, and copy/paste your secrets into that file.\n\npriority_high\nImportant\n\nBe sure to add this file to your .gitignore so you don't commit your secrets!\n\nWas this page helpful?\n\nthumb_up\nYes\nthumb_down\nNo\nedit\nSuggest edits\nforum\nStill have questions?\n\nOur forums are full of helpful information and Streamlit experts.\n\nPrevious:\nConnect to data sources\nNext:\nShare your app\nHome\nContact Us\nCommunity\n\nCopyright \u00a9 2023, Streamlit Inc.\n\nSecrets management - Streamlit Docs", "source": "streamlit-docs.txt"}
|