Araê Souza
Araê Souza

Reputation: 79

Using observeEvent to render a table in golem app

I'm new to the golem package, so new that I'm struggling with basic shiny operations. At this point I'm not able to render a table based on an observeEvent triggered by an action button. This module is supposed to scrape the co-authors of any researcher when the link to the google scholar page is provided. Nothing happens when I click the button. Can you help me figure out what I am doing wrong?


#' seleciona_autores UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd 
#'
#' @importFrom shiny NS tagList 
mod_seleciona_autores_ui <- function(id){
  ns <- NS(id)
  tagList(
    shiny::textInput(
      'link',
      label = 'Link para o google scholar',
      value = ''
    ),
    shiny::actionButton(
      'pesquisar_autores',
      'Pesquisar autores!'
    ),
    tableOutput(ns('lista_parceiros'))
 
  )
}
    
#' seleciona_autores Server Functions
#'
#' @noRd 
mod_seleciona_autores_server <- function(id){
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    
    observeEvent(input$pesquisar_autores, {
      forecasts <- rvest::read_html(input$link) %>%
        rvest::html_nodes(".gsc_a_tr") %>%
        rvest::html_nodes(".gsc_a_t") %>%
        rvest::html_element("div") %>%
        rvest::html_text()
      
      
      
      parceiros <- data.frame(table(trimws(unlist(strsplit(forecasts, ",")))))
      
      parceiros <- parceiros[parceiros$Var1 != '...',]
      
      parceiros <- parceiros[order(parceiros$Freq, decreasing = TRUE),]
      
      colnames(parceiros) <- c('Autor', 'Quantidade de trabalhos')
      
      output$lista_parceiros <- renderTable({
        parceiros
      })
    })
 
  })
}

Upvotes: 0

Views: 302

Answers (1)

Colin FAY
Colin FAY

Reputation: 5109

As stated by YBS, it's a missing ns(). This is the number one answer to "my module doesn't display" :)

FWIW we're working on having a way to check this inside {golem} so that you don't forget to add them.

Colin

Upvotes: 3

Related Questions