T Le commited on
Commit
747bf26
·
1 Parent(s): 06e7e95

Testing R packages

Browse files
Files changed (3) hide show
  1. packages.txt +4 -1
  2. pages/10 WordCloud.py +40 -12
  3. pages/Rtest.py +61 -0
packages.txt CHANGED
@@ -1 +1,4 @@
1
- chromium-driver
 
 
 
 
1
+ chromium-driver
2
+ r-base
3
+ r-basr-dev
4
+ r-cran-ggplot2
pages/10 WordCloud.py CHANGED
@@ -33,6 +33,7 @@ with st.popover("🔗 Menu"):
33
  st.page_link("pages/8 Shifterator.py", label="Shifterator", icon="8️⃣")
34
  st.page_link("pages/9 Summarization.py", label = "Summarization",icon ="9️⃣")
35
  st.page_link("pages/10 WordCloud.py", label = "WordCloud", icon = "🔟")
 
36
 
37
  st.header("Wordcloud", anchor=False)
38
  st.subheader('Put your file here...', anchor=False)
@@ -72,25 +73,52 @@ def read_csv(uploaded_file):
72
  uploaded_file = st.file_uploader('', type=['txt'], on_change=reset_all)
73
 
74
 
 
75
  if uploaded_file is not None:
76
- try:
77
- extype = get_ext(uploaded_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- if extype.endswith(".txt"):
80
- fulltext = read_txt(uploaded_file)
 
81
 
82
- wordcloud = WordCloud().generate(fulltext)
83
- img = wordcloud.to_image()
 
 
 
 
 
 
84
 
85
- with st.container(border=True):
86
- st.image(img)
87
 
88
- elif extype.endswith(".csv"):
89
- texts = read_csv(uploaded_file)
90
 
91
 
92
 
93
 
94
 
95
- except Exception as e:
96
- st.write(e)
 
33
  st.page_link("pages/8 Shifterator.py", label="Shifterator", icon="8️⃣")
34
  st.page_link("pages/9 Summarization.py", label = "Summarization",icon ="9️⃣")
35
  st.page_link("pages/10 WordCloud.py", label = "WordCloud", icon = "🔟")
36
+ st.page_link("pages/Rtest.py",label = "rtesting")
37
 
38
  st.header("Wordcloud", anchor=False)
39
  st.subheader('Put your file here...', anchor=False)
 
73
  uploaded_file = st.file_uploader('', type=['txt'], on_change=reset_all)
74
 
75
 
76
+
77
  if uploaded_file is not None:
78
+
79
+ tab1, tab2, tab3 = st.tabs(["📈 Generate visualization", "📃 Reference", "⬇️ Download Help"])
80
+
81
+ with tab1:
82
+ c1, c2 = st.columns(2)
83
+
84
+ with c1:
85
+ max_font = st.number_input("Max Font Size", min_value = 1, value = 100, on_change=reset_all)
86
+ max_words = st.number_input("Max Word Count", min_value = 1, value = 250, on_change=reset_all)
87
+ background = st.selectbox("Background color", ["white","black"], on_change=reset_all)
88
+
89
+
90
+ with c2:
91
+ words_to_remove = st.text_input("Remove specific words. Separate words by semicolons (;)")
92
+ stopwords = words_to_remove.split(';')
93
+ image_width = st.number_input("Image width", value = 400, on_change=reset_all)
94
+ image_height = st.number_input("Image height", value = 200, on_change=reset_all)
95
+ scale = st.number_input("Scale", value = 1, on_change=reset_all)
96
+
97
+ try:
98
+ extype = get_ext(uploaded_file)
99
 
100
+ if extype.endswith(".txt"):
101
+ if st.button("Submit"):
102
+ fulltext = read_txt(uploaded_file)
103
 
104
+ wordcloud = WordCloud(max_font_size = max_font,
105
+ max_words = max_words,
106
+ background_color=background,
107
+ stopwords = stopwords,
108
+ height = image_height,
109
+ width = image_width,
110
+ scale = scale).generate(fulltext)
111
+ img = wordcloud.to_image()
112
 
113
+ with st.container(border=True):
114
+ st.image(img, use_container_width=True)
115
 
116
+ elif extype.endswith(".csv"):
117
+ texts = read_csv(uploaded_file)
118
 
119
 
120
 
121
 
122
 
123
+ except Exception as e:
124
+ st.write(e)
pages/Rtest.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import subprocess
3
+
4
+ # ===config===
5
+ st.set_page_config(
6
+ page_title="Coconut",
7
+ page_icon="🥥",
8
+ layout="wide",
9
+ initial_sidebar_state="collapsed"
10
+ )
11
+
12
+ hide_streamlit_style = """
13
+ <style>
14
+ #MainMenu
15
+ {visibility: hidden;}
16
+ footer {visibility: hidden;}
17
+ [data-testid="collapsedControl"] {display: none}
18
+ </style>
19
+ """
20
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
21
+
22
+ with st.popover("🔗 Menu"):
23
+ st.page_link("https://www.coconut-libtool.com/", label="Home", icon="🏠")
24
+ st.page_link("pages/1 Scattertext.py", label="Scattertext", icon="1️⃣")
25
+ st.page_link("pages/2 Topic Modeling.py", label="Topic Modeling", icon="2️⃣")
26
+ st.page_link("pages/3 Bidirected Network.py", label="Bidirected Network", icon="3️⃣")
27
+ st.page_link("pages/4 Sunburst.py", label="Sunburst", icon="4️⃣")
28
+ st.page_link("pages/5 Burst Detection.py", label="Burst Detection", icon="5️⃣")
29
+ st.page_link("pages/6 Keywords Stem.py", label="Keywords Stem", icon="6️⃣")
30
+ st.page_link("pages/7 Sentiment Analysis.py", label="Sentiment Analysis", icon="7️⃣")
31
+ st.page_link("pages/8 Shifterator.py", label="Shifterator", icon="8️⃣")
32
+ st.page_link("pages/9 Summarization.py", label = "Summarization",icon ="9️⃣")
33
+ st.page_link("pages/10 WordCloud.py", label = "WordCloud", icon = "🔟")
34
+
35
+ st.header("R testing", anchor=False)
36
+
37
+ #========unique id========
38
+ @st.cache_resource(ttl=3600)
39
+ def create_list():
40
+ l = [1, 2, 3]
41
+ return l
42
+
43
+ l = create_list()
44
+ first_list_value = l[0]
45
+ l[0] = first_list_value + 1
46
+ uID = str(l[0])
47
+
48
+ #===clear cache===
49
+ def reset_all():
50
+ st.cache_data.clear()
51
+
52
+ if st.button("Test"):
53
+ process2 = subprocess.Popen(["Rscript", "pages/testr.R"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
54
+ result2 = process2.communicate()
55
+ with st.container(border=True):
56
+ st.image('plot.png')
57
+
58
+
59
+
60
+
61
+