Update app.R
Browse files
app.R
CHANGED
@@ -1,141 +1,43 @@
|
|
1 |
library(shiny)
|
2 |
-
library(shinyalert)
|
3 |
library(shinythemes)
|
4 |
-
library(
|
5 |
-
library(shinyjs)
|
6 |
-
library(httr)
|
7 |
-
library(bslib)
|
8 |
-
library(thematic)
|
9 |
-
library(gtrendsR)
|
10 |
-
library(plotly)
|
11 |
-
library(dplyr)
|
12 |
-
library(ggplot2)
|
13 |
|
14 |
-
options(spinner.color = "lightblue",
|
15 |
-
spinner.color.background = "#ffffff",
|
16 |
-
spinner.size = 2)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
hidden(tags$div(id = "about",h5("TrendChecker is a web application that enables users to monitor the search popularity of any subject of interest over time,
|
36 |
-
and across different countries by calling the Google trend api. Search hit of 100 is the indicator of optimum popularity, while other hits are measured relative to the optimum."))),h4(strong("Controls")),hr(),
|
37 |
-
textInput("text",strong("Enter Search Term")),
|
38 |
-
checkboxGroupInput("check",strong("Select Country(ies)"),choices = c("USA" = "US","UK" = "GB","Germany" = "DE","Netherlands" = "NL","Nigeria" = "NG","Japan" = "JP")),
|
39 |
-
radioButtons("radio",strong("Choose Trend Source"),choices = c("Web","News","YouTube","Images")),
|
40 |
-
radioButtons("time",strong("Select Time Frame"),choices = c("Last Hour","Last Four Hours","Last Day","Last Seven Days","Past 30 Days","Past 90 Days","Past 12 Months","Last Five Years")),
|
41 |
-
actionButton("run",strong("Run Search"),icon("caret-right"))
|
42 |
-
),
|
43 |
-
mainPanel(
|
44 |
-
withSpinner(plotOutput("plot", width = "113%", height = "450px"),type = 8),
|
45 |
-
downloadButton("plot_download","Download",icon = icon("download"))),
|
46 |
-
|
47 |
-
|
48 |
-
))
|
49 |
-
))
|
50 |
-
|
51 |
-
# Define server logic required to run query
|
52 |
-
|
53 |
-
server <- function(input, output,session) {
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
}
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
radio_input <- reactive(switch(input$radio,
|
68 |
-
"Web" = "web",
|
69 |
-
"News" = "news",
|
70 |
-
"YouTube" = "youtube",
|
71 |
-
"Images" = "images"))
|
72 |
-
|
73 |
-
radio_time <- reactive(switch(input$time,
|
74 |
-
"Last Hour" = "now 1-H",
|
75 |
-
"Last Four Hours" = "now 4-H",
|
76 |
-
"Last Day" = "now 1-d",
|
77 |
-
"Last Seven Days" = "now 7-d",
|
78 |
-
"Past 30 Days" = "today 1-m",
|
79 |
-
"Past 90 Days" = "today 3-m",
|
80 |
-
"Past 12 Months" = "today 12-m",
|
81 |
-
"Last Five Years" = "today+5-y"))
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
text_input <- reactive(input$text)
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
## Write the function
|
91 |
-
|
92 |
-
trend <- function(){
|
93 |
-
|
94 |
-
gt <- gtrends(keyword = text_input(),geo = check_input(),gprop = radio_input(),
|
95 |
-
time = radio_time())
|
96 |
-
|
97 |
-
p <- plot(gt)
|
98 |
-
|
99 |
-
return(p)
|
100 |
}
|
101 |
-
|
102 |
-
## Convert to reactive function
|
103 |
-
|
104 |
-
trend2 <- eventReactive(input$run,{
|
105 |
-
trend()
|
106 |
-
})
|
107 |
-
|
108 |
-
## Create interactive plot
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
withProgress(message = "Fetching data",
|
113 |
-
detail = "This may take a while...",value = 0,{
|
114 |
-
|
115 |
-
for (i in 1:40){
|
116 |
-
|
117 |
-
incProgress(1/40)
|
118 |
-
Sys.sleep(0.4)
|
119 |
-
}
|
120 |
-
})
|
121 |
-
|
122 |
-
req(input$run)
|
123 |
-
trend2()
|
124 |
-
|
125 |
-
})
|
126 |
-
|
127 |
-
output$plot_download <- downloadHandler(
|
128 |
-
filename = function(){
|
129 |
-
paste("graph",".jpg",sep = "")
|
130 |
-
},
|
131 |
-
content = function(file){
|
132 |
-
jpeg(file)
|
133 |
-
trend()
|
134 |
-
dev.off()
|
135 |
-
}
|
136 |
-
)
|
137 |
-
|
138 |
-
}
|
139 |
|
140 |
-
# Run the application
|
141 |
-
shinyApp(ui = ui, server = server)
|
|
|
1 |
library(shiny)
|
|
|
2 |
library(shinythemes)
|
3 |
+
library(GWalkR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
5 |
|
6 |
+
ui <- fluidPage(
|
7 |
+
title = "Data Explorer",
|
8 |
+
theme = shinytheme("cyborg"),
|
9 |
+
|
10 |
+
tags$h3(id = "title", tags$strong("Graphic-Walker Data Explorer"),style = "text-align:center;color:lightblue;"),
|
11 |
+
sidebarLayout(
|
12 |
+
sidebarPanel(width = 3, fileInput("target_upload",h5(strong("Click to Upload CSV File"),style = "color:lightblue;"),
|
13 |
+
accept = c("text/csv"),
|
14 |
+
placeholder = "No file selected"),
|
15 |
+
br(),br(),a(href = "https://github.com/Kanaries/GWalkR",h6("Learn More",style = "color:lightblue;"),target = "_blank",style = "text-decoration: none;")),
|
16 |
+
mainPanel(gwalkrOutput(outputId = "explorer",width = "114%")
|
17 |
+
)
|
18 |
+
)
|
19 |
+
|
20 |
)
|
21 |
|
22 |
+
server <- function(input,output,session){
|
23 |
+
file_upload <- reactive({
|
24 |
+
inFile <- input$target_upload
|
25 |
+
if(is.null(inFile)){return(NULL)}
|
26 |
+
data <- read.csv(inFile$datapath,header = TRUE,sep = ",")
|
27 |
+
return(data)
|
28 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
output$explorer <- renderGwalkr({
|
31 |
+
tryCatch(
|
32 |
+
{
|
33 |
+
gwalkr(file_upload())
|
34 |
+
},
|
35 |
+
error = function(e){
|
36 |
+
message("Could not display interface")
|
37 |
+
}
|
38 |
+
)
|
39 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
shinyApp(ui,server)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
|
|
|