How to use the streamlit.selectbox function in streamlit

To help you get started, we’ve selected a few streamlit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MarcSkovMadsen / awesome-streamlit / gallery / iris_classification / iris.py View on Github external
def show_scatter_plot(selected_species_df: pd.DataFrame):
    """## Component to show a scatter plot of two features for the selected species

    Arguments:
        selected_species_df {pd.DataFrame} -- A DataFrame with the same columns as the
            source_df iris dataframe
    """
    st.subheader("Scatter plot")
    feature_x = st.selectbox("Which feature on x?", selected_species_df.columns[0:4])
    feature_y = st.selectbox("Which feature on y?", selected_species_df.columns[0:4])

    fig = px.scatter(selected_species_df, x=feature_x, y=feature_y, color="variety")
    st.plotly_chart(fig)
github MarcSkovMadsen / awesome-streamlit / gallery / country_indicators / streamlit_country_indicators.py View on Github external
def __init__(self, df):
        self._df = df.copy(deep=True)  # Deep copy to avoid st.cache problems
        available_indicators = self._df["Indicator Name"].unique()
        min_value = min(df["Year"])
        max_value = max(df["Year"])

        st.sidebar.markdown(EXPLANATION, unsafe_allow_html=True)
        x_indicator = st.selectbox("Select indicator x", available_indicators, 0)
        y_indicator = st.selectbox("Select indicator y", available_indicators, 1)
        plotly_chart = st.empty()

        # Hack to seperate plot and slider
        st.markdown("<br><br>", unsafe_allow_html=True)
        year_range = st.slider(
            "Select min and max Year",
            min_value=min_value,
            max_value=max_value,
            value=[min_value, max_value],
        )

        fig = self._create_plot(x_indicator, y_indicator, year_range)
        plotly_chart.plotly_chart(fig, width=0, height=300)
github Jcharis / Streamlit_DataScience_Apps / news_classifier_nlp-app / app.py View on Github external
<h1 style="color:white;text-align:center;">Streamlit ML App </h1>
	

	"""
	st.markdown(html_temp,unsafe_allow_html=True)

	activity = ['Prediction','NLP']
	choice = st.sidebar.selectbox("Select Activity",activity)


	if choice == 'Prediction':
		st.info("Prediction with ML")

		news_text = st.text_area("Enter News Here","Type Here")
		all_ml_models = ["LR","RFOREST","NB","DECISION_TREE"]
		model_choice = st.selectbox("Select Model",all_ml_models)

		prediction_labels = {'business': 0,'tech': 1,'sport': 2,'health': 3,'politics': 4,'entertainment': 5}
		if st.button("Classify"):
			st.text("Original Text::\n{}".format(news_text))
			vect_text = news_cv.transform([news_text]).toarray()
			if model_choice == 'LR':
				predictor = load_prediction_models("models/newsclassifier_Logit_model.pkl")
				prediction = predictor.predict(vect_text)
				# st.write(prediction)
			elif model_choice == 'RFOREST':
				predictor = load_prediction_models("models/newsclassifier_RFOREST_model.pkl")
				prediction = predictor.predict(vect_text)
				# st.write(prediction)
			elif model_choice == 'NB':
				predictor = load_prediction_models("models/newsclassifier_NB_model.pkl")
				prediction = predictor.predict(vect_text)
github MarcSkovMadsen / awesome-streamlit / gallery / sentiment_analyzer / sentiment_analyzer.py View on Github external
file_markdown = "Source: \n"
file_markdown += ", ".join([f"[{file}]({ROOT_URL+file})" for file in FILES])
st.markdown(file_markdown)

with st.spinner("Extracting source data..."):
    all_data = get_all_data()

    source_data = pd.DataFrame(
        preprocessing_data(all_data), columns=["review", "sentiment"]
    )
    source_data["sentiment"] = source_data["sentiment"].map(
        {"0": "Negative", "1": "Positive"}
    )
    st.info(f"{len(source_data)} rows where extract with **succes**!")

top = st.selectbox(
    "Select number of rows to show", [5, 10, 25, 50, 100, len(source_data)]
)
st.table(source_data.head(top))

st.subheader("Train the algorithm")
with st.spinner("Training algorithm..."):
    training_data, evaluation_data = preprocessing_step()
    vectorizer = CountVectorizer(binary="true")
    classifier = training_step(training_data, vectorizer)
    st.info("The algorithm was trained with **success**!")


st.title("Try the algorithm here!")
write_here = "Write Here..."
review = st.text_input("Enter a review for classification by the algorithm", write_here)
if st.button("Predict Sentiment"):
github Jcharis / Streamlit_DataScience_Apps / Iris_EDA_Web_App / iris_app.py View on Github external
# Show Dimensions and Shape of Dataset
    data_dim = st.radio('What Dimension Do You Want to Show',('Rows','Columns'))
    if data_dim == 'Rows':
    	st.text("Showing Length of Rows")
    	st.write(len(data))
    if data_dim == 'Columns':
    	st.text("Showing Length of Columns")
    	st.write(data.shape[1])

    # Show Summary of Dataset
    if st.checkbox("Show Summary of Dataset"):
    	st.write(data.describe())

    # Selection of Columns
    species_option = st.selectbox('Select Columns',('sepal_length','sepal_width','petal_length','petal_width','species'))
    if species_option == 'sepal_length':
    	st.write(data['sepal_length'])
    elif species_option == 'sepal_width':
    	st.write(data['sepal_width'])
    elif species_option == 'petal_length':
    	st.write(data['petal_length'])
    elif species_option == 'petal_width':
    	st.write(data['petal_width'])
    elif species_option == 'species':
    	st.write(data['species'])
    else:
    	st.write("Select A Column")

    # Show Plots
    if st.checkbox("Simple Bar Plot with Matplotlib "):
    	data.plot(kind='bar')
github abhinavkashyap / sciwing / sciwing / app / ner_demo.py View on Github external
"journal",
        "location",
        "note",
        "pages",
        "publisher",
        "tech",
        "title",
        "volume",
    ]
    labels_legend = ""
    for label in labels:
        labels_legend += label_pill.format(label.upper())

    st.write(labels_legend, unsafe_allow_html=True)

    text_selected = st.selectbox(
        label="Select a Citation",
        options=[
            "Calzolari, N. (1982) Towards the organization of lexical definitions on a database structure. In E. Hajicova (Ed.), COLING '82 Abstracts, Charles University, Prague, pp.61-64.",
            "Caraballo, S.A. (1999) Automatic construction of a hypernym-labeled noun hierarchy. In Proceedings of the 37th Annual Meeting of the Association for Computational Linguistics (ACL'99), College Park, Maryland, pp. 120-126.",
        ],
    )

    user_text = st.text_input(label="Enter a citation string", value=text_selected)
    parse_button_clicked = st.button("Parse Citation")


elif model_selected == "I2B2 Clinical Notes Tagging":
    st.title("I2B2 Clinical Notes Tagging")
    st.markdown(
        "Clinical Natural Language Processing helps in identifying salient information from clinical notes."
        "Here, we have trained a neural network model on the **i2b2: Informatics for Integrating Biology and the Bedside** dataset."
github MarcSkovMadsen / awesome-streamlit / src / pages / gallery / index.py View on Github external
ast.shared.components.title_awesome("Gallery")
    apps = get_apps()

    st.sidebar.title("Gallery")
    is_awesome = st.sidebar.checkbox("Awesome apps only", True)
    show_source_code = st.sidebar.checkbox("Show Source Code", True)
    if is_awesome:
        apps = ast.core.services.resources.filter_by_is_awesome(apps)

    tags = st.multiselect("Select Tag(s)", get_tags(apps))
    apps = ast.core.services.resources.filter_by_tags(apps, tags)

    authors = get_authors(apps)
    author_all = ast.shared.models.Author(name="All", url="")
    authors = [author_all] + authors
    author = st.selectbox("Select Author", authors)

    if author != author_all:
        apps = get_apps_by_author(apps, author)

    app_index = 0
    if author == ast.database.apps_in_gallery.DEFAULT_APP_IN_GALLERY.author:
        if ast.database.apps_in_gallery.DEFAULT_APP_IN_GALLERY in apps:
            app_index = apps.index(ast.database.apps_in_gallery.DEFAULT_APP_IN_GALLERY)

    apps = ast.core.services.resources.sort_resources(apps)
    run_app = st.selectbox("Select the App", apps, index=app_index)
    app_credits = st.empty()

    app_credits.markdown(
        f"""Resources: [Author]({run_app.author.url}), [App Code]({run_app.url})"""
    )
github MarcSkovMadsen / awesome-streamlit / src / pages / resources.py View on Github external
def write():
    """Writes content to the app"""
    ast.shared.components.title_awesome("Resources")
    st.sidebar.title("Resources")
    tags = ast.shared.components.multiselect(
        "Select Tag(s)", options=ast.database.TAGS, default=[]
    )

    author_all = ast.shared.models.Author(name="All", url="")
    author = st.selectbox("Select Author", options=[author_all] + ast.database.AUTHORS)
    if author == author_all:
        author = None
    show_awesome_resources_only = st.checkbox("Show Awesome Resources Only", value=True)
    if not tags:
        st.info(
            """Please note that **we list each resource under a most important tag only!**"""
        )
    resource_section = st.empty()

    with st.spinner("Loading resources ..."):
        markdown = resources.get_resources_markdown(
            tags, author, show_awesome_resources_only
        )
        resource_section.markdown(markdown)

    if st.sidebar.checkbox("Show Resource JSON"):
github JAVI897 / ML-Metrics / src / pages / other_graphs.py View on Github external
if len(data) == 0:
        st.error("There's not data")
    
    else:
        df_graphs=pd.DataFrame({"graphs":["Precision and Recall vs Decision threshold", 
                                          "True positive rate and False positive rate vs Decision threshold"]})

        #Sensitivity and 1 - specificity vs Decision threshold

        #Habría que cambiarlo de momento añadimos datos por aquí
        #prediction_1=np.load("data/prediction_1.npy")
        #Y_Test_1=np.load("data/Y_Test_1.npy")
        #data = [(Y_Test_1, prediction_1)]
        keys = list(data.keys())
        model = st.selectbox(label="Select a model:", options = keys, index = 0 )
        
        graphs = metrics.Graphs([data[model]])

        st.sidebar.title("Other graphs")
        option_graphs = st.sidebar.selectbox("Select",df_graphs["graphs"])
        option_threshold,option_fill,option_legend,number_threshold= configuration(other_graph = True)

        if option_graphs == "Precision and Recall vs Decision threshold":
            st.title("Precision and Recall vs Decision threshold")
            if option_threshold: 
                methods_list = methods_Precision_and_Recall()
            else: 
                methods_list=None
            g = other_graphics(graphs, option_graphs, option_threshold,option_legend,methods_list, number_threshold)
            st.plotly_chart(g)