giswqs commited on
Commit
b1fc4cc
1 Parent(s): 2b93ee2

Update st.cache

Browse files
Files changed (5) hide show
  1. apps/h_index.py +3 -3
  2. apps/journal.py +3 -3
  3. apps/researcher.py +6 -11
  4. multiapp.py +3 -2
  5. streamlit_app.py +2 -2
apps/h_index.py CHANGED
@@ -9,7 +9,7 @@ if "dsl" not in st.session_state:
9
  st.session_state["dsl"] = scholarpy.Dsl()
10
 
11
 
12
- @st.cache
13
  def the_H_function(sorted_citations_list, n=1):
14
  """from a list of integers [n1, n2 ..] representing publications citations,
15
  return the max list-position which is >= integer
@@ -41,7 +41,7 @@ def dim_login(key=None, endpoint=None):
41
  raise Exception("Failed to login to Dimensions")
42
 
43
 
44
- @st.cache
45
  def get_pubs_df(dsl, researcher_id):
46
 
47
  q = """search publications where researchers.id = "{}" return publications[id+title+doi+times_cited] sort by times_cited limit 1000"""
@@ -50,7 +50,7 @@ def get_pubs_df(dsl, researcher_id):
50
  return pubs.as_dataframe()
51
 
52
 
53
- @st.cache
54
  def get_citations(df):
55
  return list(df.fillna(0)["times_cited"])
56
 
 
9
  st.session_state["dsl"] = scholarpy.Dsl()
10
 
11
 
12
+ @st.cache_data
13
  def the_H_function(sorted_citations_list, n=1):
14
  """from a list of integers [n1, n2 ..] representing publications citations,
15
  return the max list-position which is >= integer
 
41
  raise Exception("Failed to login to Dimensions")
42
 
43
 
44
+ @st.cache_data
45
  def get_pubs_df(dsl, researcher_id):
46
 
47
  q = """search publications where researchers.id = "{}" return publications[id+title+doi+times_cited] sort by times_cited limit 1000"""
 
50
  return pubs.as_dataframe()
51
 
52
 
53
+ @st.cache_data
54
  def get_citations(df):
55
  return list(df.fillna(0)["times_cited"])
56
 
apps/journal.py CHANGED
@@ -25,13 +25,13 @@ def read(filename_dot_csv):
25
  return df
26
 
27
 
28
- @st.cache
29
  def get_token():
30
 
31
  return os.environ.get("DIM_TOKEN")
32
 
33
 
34
- @st.cache
35
  def get_journals():
36
 
37
  with open("data/journals.json") as f:
@@ -40,7 +40,7 @@ def get_journals():
40
  return journals
41
 
42
 
43
- @st.cache
44
  def read_excel(sheet_name):
45
 
46
  df = pd.read_excel(
 
25
  return df
26
 
27
 
28
+ @st.cache_data
29
  def get_token():
30
 
31
  return os.environ.get("DIM_TOKEN")
32
 
33
 
34
+ @st.cache_data
35
  def get_journals():
36
 
37
  with open("data/journals.json") as f:
 
40
  return journals
41
 
42
 
43
+ @st.cache_data
44
  def read_excel(sheet_name):
45
 
46
  df = pd.read_excel(
apps/researcher.py CHANGED
@@ -9,7 +9,7 @@ if "dsl" not in st.session_state:
9
  st.session_state["dsl"] = scholarpy.Dsl()
10
 
11
 
12
- @st.cache(allow_output_mutation=True)
13
  def get_geonames():
14
  return scholarpy.get_geonames()
15
 
@@ -57,8 +57,7 @@ def annual_collaborators(pubs, col="year"):
57
  def annual_citations(pubs, col="year"):
58
  if pubs is not None:
59
  df = pubs.groupby([col]).sum()
60
- df2 = pd.DataFrame(
61
- {"year": df.index, "citations": df["times_cited"].values})
62
  fig = px.bar(
63
  df2,
64
  x="year",
@@ -107,8 +106,7 @@ def app():
107
 
108
  info_df = json_to_df(id_info, transpose=True)
109
  info_df.rename(
110
- columns={info_df.columns[0]: "Type",
111
- info_df.columns[1]: "Value"},
112
  inplace=True,
113
  )
114
  with row1_col1:
@@ -132,14 +130,12 @@ def app():
132
 
133
  with row1_col2:
134
  st.header("Researcher statistics")
135
- columns = ["pubs", "collaborators",
136
- "institutions", "cities"]
137
  selected_columns = st.multiselect(
138
  "Select attributes to display:", columns, columns
139
  )
140
  if selected_columns:
141
- fig = scholarpy.annual_stats_barplot(
142
- df1, selected_columns)
143
  st.plotly_chart(fig)
144
  leafmap.st_download_button(
145
  "Download data",
@@ -171,8 +167,7 @@ def app():
171
  )
172
 
173
  st.header("Publication counts with collaborators")
174
- collaborators = dsl.search_researcher_collaborators(
175
- id, pubs)
176
  markdown = f"""
177
  - Total number of collaborators: **{len(collaborators)}**
178
  """
 
9
  st.session_state["dsl"] = scholarpy.Dsl()
10
 
11
 
12
+ @st.cache_data
13
  def get_geonames():
14
  return scholarpy.get_geonames()
15
 
 
57
  def annual_citations(pubs, col="year"):
58
  if pubs is not None:
59
  df = pubs.groupby([col]).sum()
60
+ df2 = pd.DataFrame({"year": df.index, "citations": df["times_cited"].values})
 
61
  fig = px.bar(
62
  df2,
63
  x="year",
 
106
 
107
  info_df = json_to_df(id_info, transpose=True)
108
  info_df.rename(
109
+ columns={info_df.columns[0]: "Type", info_df.columns[1]: "Value"},
 
110
  inplace=True,
111
  )
112
  with row1_col1:
 
130
 
131
  with row1_col2:
132
  st.header("Researcher statistics")
133
+ columns = ["pubs", "collaborators", "institutions", "cities"]
 
134
  selected_columns = st.multiselect(
135
  "Select attributes to display:", columns, columns
136
  )
137
  if selected_columns:
138
+ fig = scholarpy.annual_stats_barplot(df1, selected_columns)
 
139
  st.plotly_chart(fig)
140
  leafmap.st_download_button(
141
  "Download data",
 
167
  )
168
 
169
  st.header("Publication counts with collaborators")
170
+ collaborators = dsl.search_researcher_collaborators(id, pubs)
 
171
  markdown = f"""
172
  - Total number of collaborators: **{len(collaborators)}**
173
  """
multiapp.py CHANGED
@@ -1,8 +1,9 @@
1
  """Frameworks for running multiple Streamlit applications as a single app.
2
  """
 
3
  import streamlit as st
4
 
5
- # app_state = st.experimental_get_query_params()
6
  # app_state = {k: v[0] if isinstance(v, list) else v for k, v in app_state.items()} # fetch the first item in each query string as we don't have multiple values for each query string key in this example
7
 
8
 
@@ -41,7 +42,7 @@ class MultiApp:
41
  self.apps.append({"title": title, "function": func})
42
 
43
  def run(self):
44
- app_state = st.experimental_get_query_params()
45
  app_state = {
46
  k: v[0] if isinstance(v, list) else v for k, v in app_state.items()
47
  } # fetch the first item in each query string as we don't have multiple values for each query string key in this example
 
1
  """Frameworks for running multiple Streamlit applications as a single app.
2
  """
3
+
4
  import streamlit as st
5
 
6
+ # app_state = st.query_params
7
  # app_state = {k: v[0] if isinstance(v, list) else v for k, v in app_state.items()} # fetch the first item in each query string as we don't have multiple values for each query string key in this example
8
 
9
 
 
42
  self.apps.append({"title": title, "function": func})
43
 
44
  def run(self):
45
+ app_state = st.query_params
46
  app_state = {
47
  k: v[0] if isinstance(v, list) else v for k, v in app_state.items()
48
  } # fetch the first item in each query string as we don't have multiple values for each query string key in this example
streamlit_app.py CHANGED
@@ -27,13 +27,13 @@ apps = {
27
  "researcher": {"title": "Researcher", "icon": "person-circle"},
28
  "orcid": {"title": "ORCID", "icon": "person-square"},
29
  "organization": {"title": "Organization", "icon": "building"},
30
- "google": {"title": "Google Scholar", "icon": "google"},
31
  }
32
 
33
 
34
  titles = [app["title"] for app in apps.values()]
35
  icons = [app["icon"] for app in apps.values()]
36
- params = st.experimental_get_query_params()
37
 
38
  if "page" in params:
39
  default_index = int(titles.index(params["page"][0].lower()))
 
27
  "researcher": {"title": "Researcher", "icon": "person-circle"},
28
  "orcid": {"title": "ORCID", "icon": "person-square"},
29
  "organization": {"title": "Organization", "icon": "building"},
30
+ # "google": {"title": "Google Scholar", "icon": "google"},
31
  }
32
 
33
 
34
  titles = [app["title"] for app in apps.values()]
35
  icons = [app["icon"] for app in apps.values()]
36
+ params = st.query_params
37
 
38
  if "page" in params:
39
  default_index = int(titles.index(params["page"][0].lower()))