-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
169 lines (133 loc) · 6.06 KB
/
Copy pathapp.R
File metadata and controls
169 lines (133 loc) · 6.06 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Packages ----
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library(jsonlite)
library(here)
library(tidytext)
library(paletteer)
library(highcharter)
library(shiny)
library(shinyWidgets)
library(styler)
library(shinydashboard)
#
#library(shinydashboardPlus)
#
library(rwhatsapp)
library(tools)
library(waiter)
library(tidyverse)
options(highcharter.theme = hc_theme_hcrt())
newtheme <- hc_theme_merge(
getOption("highcharter.theme"),
hc_theme(chart = list(backgroundColor = "transparent"),
colors =
c("#332859",
(paletteer_d("ggsci::nrc_npg") %>%
as.character() %>%
str_sub(1,7))
))
)
options(highcharter.theme = newtheme)
# hchart(cars, "scatter", hcaes(speed, dist))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ Source functions ----
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source(here("scripts/functions/misc_functions.R"))
source(here("scripts/functions/whatsapp_txt_to_clean_df.R"))
source(here("scripts/functions/json_list_to_clean_df.R"))
# donut plots
source(here("scripts/functions/word_count_donutplot.R"))
source(here("scripts/functions/message_count_donutplot.R"))
# message length
source(here("scripts/functions/avg_msg_length_barplot.R"))
# messages over time
source(here("scripts/functions/msg_freq_over_time_lineplot.R"))
source(here("scripts/functions/msg_freq_weekly_radialplot.R"))
# top words and phrases
source(here("scripts/functions/top_words_barplot.R"))
source(here("scripts/functions/top_ngrams_barplot.R"))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~ ui ----
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ui <-dashboardPage(
header = dashboardHeader(disable = T, title = "Analyze your texts today at chartmychats.com", titleWidth = "95vh",
tags$li(class = "dropdown", tags$li(HTML("<a href='https://www.w3schools.com/' target= '_blank' >About</a>")))),
sidebar = dashboardSidebar(disable = T),
body = dashboardBody(
use_waiter(), # include dependencies
waiter_on_busy(),
setBackgroundImage(
src = "https://www.fonewalls.com/wp-content/uploads/Lavender-Gradient-Wallpaper.jpg",
shinydashboard = TRUE),
fluidRow(
column(width = 3,
box(width = NULL,
div(style = 'overflow-x: scroll; ',
HTML("<h2>Prototype Shiny App to analyse FB and Whatsapp messages.</h2> <br>
Steps to export your messages:
<a href='https://tinyurl.com/exportwhatsappchat' target= '_blank' >Whatsapp</a>
or
<a href='https://tinyurl.com/exportfacebookchat' target= '_blank' >Facebook</a>.<br>
Then upload a single conversation to the app.
Note that this app does NOT store any of your information.
You can view all source code for the app on my <a href='https://github.com/kendavidn/chart_my_chat' target= '_blank' >github.</a>
Got other module ideas! I'm at kendavidn@gmail.com"))
)
),
column(width = 6,
# class = "col-lg-offset-4 col-lg-4 col-md-offset-2 col-md-8 col-sm-offset-1 col-sm-10",
fileInput("file1", "Choose File", accept = c(".json", ".txt"), width = "100%")
)
,
column(width = 3,
dropdownButton(tags$h4("Control Outputs"),
"Will add options to subset by sender, dates",
icon = icon("gear"), status = "info"),
dropdownButton(tags$h4("Control Outputs"),
"will add information about non-obvious text analysis decisions",
icon = icon("info"), status = "info")
)
),
fluidRow(
column(width = 12,
column(width = 4, highchartOutput("message_count_donutplot")),
column(width = 4, highchartOutput("word_count_donutplot")),
column(width = 4, highchartOutput("avg_msg_length_barplot"))
)
),
fluidRow(
column(width = 8, highchartOutput("msg_freq_over_time_lineplot")),
column(width = 4, highchartOutput("msg_freq_weekly_radialplot"))
),
fluidRow(
column(width = 12,
column(width = 6, highchartOutput("top_words_barplot")),
column(width = 6, highchartOutput("top_ngrams_barplot"))
)
)
)
)
server <- function(input, output) {
# data in
messages_df <- reactive({
file <- input$file1
req(file)
if (file_ext(file$datapath) == "txt"){
whatsapp_txt_to_clean_df(whatsapp_txt = file$datapath)
} else if (file_ext(file$datapath) == "json"){
jsonlite::fromJSON(txt = file$datapath) %>%
json_list_to_clean_df()
}
})
# analysis out
output$message_count_donutplot <- renderHighchart(messages_df() %>% message_count_donutplot())
output$word_count_donutplot <- renderHighchart(messages_df() %>% word_count_donutplot())
output$avg_msg_length_barplot <- renderHighchart(messages_df() %>% avg_msg_length_barplot())
output$msg_freq_over_time_lineplot <- renderHighchart(messages_df() %>% msg_freq_over_time_lineplot())
output$msg_freq_weekly_radialplot <- renderHighchart(messages_df() %>% msg_freq_weekly_radialplot())
output$top_words_barplot <- renderHighchart(messages_df() %>% top_words_barplot(max_nb = 30))
output$top_ngrams_barplot <- renderHighchart(messages_df() %>% top_ngrams_barplot(max_nb = 30))
}
# Run the application
shinyApp(ui = ui, server = server)