Search code examples
rshinyreactive-programmingshinydashboard

R Shiny reactive object as a vector (ggplot)


in my Shiny App I want to have textinput, action button and grapf plotted after clicking action but.

My problem is how to use in reactive in gtrends function (from gtrendsR package).

    ui <- fluidPage(

  textInput("fraza", "Wpisz fraze do wyszukania w Google Trends", "...")  
  ,actionButton("ab", "An action button")
  ,plotOutput("gtr")
)
######################
server <- function(input, output) {
  
library(gtrendsR)  
    
observeEvent(input$ab, {
  output$fraza <- renderText({input$fraza})

  zm <- reactive({input$fraza})
  library(gtrendsR)  
    gtr <- gtrends(zm)
    output$gtr <- renderPlot({plot(gtr)})
                             
                             
  
}) #zamkniecie observe
  
  } #zamkniecie server

  
###################
shinyApp(ui, server)

#################

Could You help me?


Solution

  • The output of the reactive function can be thought of as a function.

    when you use zm, you should call it like zm() and you shouldn't have an issue.