I am currently exploring the possibility of visualizing the outputs obtained from rtweet in a shiny dashboard to allow users to explore their own searches. My current blocker is the steps that are needed from the user writing the desired search and making the request via the submit button.
My first attempt was to create a reactive event but that resulted in the query being made every time there were changes in the text box. What would be the best approach to write the request and receive the visualization after the submit button is hit?
Bonus, how can I space the area between Query and Submit buttons so they don't look so cluttered on the left side?
Thanks for the pointers!
Code in progress:
library(shiny)
library(rtweet)
library(tidyverse)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput(
inputId = "hash",
label = "Query"
),
submitButton(
text = "Submit"
)
),
mainPanel(
plotOutput("Frequency")
)
)
)
server <- function(input, output) {
results <- eventReactive(input$submit, {
search_tweets(
q = input$hash,
n = 100)
})
output$Frequency <- renderPlot({
ts_plot(results(), "day")
})
}
shinyApp(ui = ui, server = server)
CodePudding user response:
Here's one way using eventReactive.
I have replaced search_tweets function with rnorm and ts_plot with simple plot for demonstration purpose.
library(shiny)
library(rtweet)
library(tidyverse)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput(
inputId = "hash",
label = "Query"
),
br(),br(),
actionButton("submit",
"Submit"
)
),
mainPanel(
plotOutput("Frequency")
)
)
)
server <- function(input, output) {
results <- eventReactive(input$submit, {
rnorm(input$hash)
})
output$Frequency <- renderPlot({
plot(results())
})
}
shinyApp(ui = ui, server = server)

