'textInput with submitButton in Shiny

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)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source