File size: 3,133 Bytes
1da1c98 cc5bd12 1da1c98 cc5bd12 1da1c98 cc5bd12 1da1c98 |
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
import os
import scholarpy
import pandas as pd
import streamlit as st
import leafmap.foliumap as leafmap
import plotly.express as px
import datetime
if "dsl" not in st.session_state:
st.session_state["dsl"] = scholarpy.Dsl()
current_year = datetime.datetime.now().year
def app():
st.title("Search Grants")
dsl = st.session_state["dsl"]
(
row1_col1,
row1_col2,
row1_col3,
row1_col4,
row1_col5,
) = st.columns([1, 0.5, 1, 1, 1])
(
row2_col1,
row2_col2,
row2_col3,
row2_col4,
row2_col5,
) = st.columns([1, 0.5, 1, 1, 1])
with row1_col1:
keywords = st.text_input("Enter a keyword to search for")
with row1_col2:
exact_match = st.checkbox("Exact match", True)
with row1_col3:
scope = st.selectbox(
"Select a search scope",
[
"concepts",
"full_data",
"investigators",
"title_abstract_only",
"title_only",
],
index=4,
)
with row1_col4:
years = st.slider(
"Select the start and end year:",
1950,
current_year + 6,
(2010, current_year + 4),
)
with row1_col5:
limit = st.slider("Select the number of grants to return", 1, 1000, 100)
if keywords:
result = dsl.search_grants_by_keyword(
keywords,
exact_match,
scope,
start_year=years[0],
end_year=years[1],
limit=limit,
)
df = scholarpy.json_to_df(result)
if limit > result.count_total:
limit = result.count_total
markdown = f"""
Returned grants: {limit} (total = {result.count_total})
"""
with row2_col1:
st.markdown(markdown)
with row2_col2:
filter = st.checkbox("Apply a filter")
if filter:
countries = []
for row in df.itertuples():
countries.append(eval(row.funder_countries)[0]["name"])
df["funder_country"] = countries
with row2_col3:
filter_by = st.selectbox(
"Select a filter",
[
"funder_country",
"funding_org_name",
"funding_org_acronym",
"research_org_name",
],
)
df["funding_org_acronym"] = df["funding_org_acronym"].astype(str)
df["research_org_name"] = df["research_org_name"].astype(str)
options = df[filter_by].unique()
options.sort()
with row2_col4:
selected = st.selectbox("Select a filter value", options)
df = df[df[filter_by] == selected]
with row2_col5:
st.write("")
if df is not None:
st.dataframe(df)
leafmap.st_download_button("Download data", df, csv_sep="\t")
|