13.1 Data
I started by setting initial values using reactiveValues()
to store user input.
First the google input
store with 4 values values$google_search <- c("Amazon", "Walmart", "Best Buy", "Target")
, time with
values$time <- "today 12-m"
and the product with values$product <- "web"
. Why don’t I want to save entries after the user clicks the submit
button? The idea is that when you start the app, the app loads all charts and tables without hitting the submit button. Then, as users enter different inputs, reactiveValues()
updates the inputs.
values <- reactiveValues(google_search = NULL,
time = NULL,
product = NULL)
observe({
if (is.null(values$google_search) &
is.null(values$time) & is.null(values$product)) {
values$google_search <- c("Amazon", "Walmart", "Best Buy", "Target")
values$time <- "today 12-m"
values$product <- "web"
}
})
observeEvent(input$submit, {
values$google_search <- input$google_search
values$time <- times()
values$product <- input$product
})
For date entry, there were two options to get user entry. Since the user selects Specify
or Date
, ifelse()
must be used to return the Date
.
times <- reactive({
req(input$time)
if (input$time == "specific") {
times <- paste0(input$dates, collapse = " ")
} else{
times <- input$time
}
return(times)
})
Now that we have all the user inputs, we can start processing the data
. gtrends()
provides the query output
- interest_over_time
- interest_by_city
- interest_by_dma
- related_queries
- related_topics
The following code shows how to apply gtrends()
to return a list of data used for this application. In this case, the R code dataout()
below is a list of the data to use interest_over_time, interest_by_region, interest_by_dma, related_queries