Using tooltips with shiny module - getting a "Error in : $ operator is invalid for atomic vectors" error

The app I am working on is getting very complicated, so I am putting a lot of the code into modules.

My plots have tooltips which were working fine on the un-modularised version. However, now I am getting a "Error in : $ operator is invalid for atomic vectors" message.

I think it's the output$my_tooltip which is causing the error.

Here is the UI function for the plot,

# UI for plot
MA_sroc_plot_UI <- function(id)   {
  ns <- NS(id)   # namespace function
  tagList(   
    plotOutput(outputId =  ns("plot"),
               click =  ns("plot_click")),
    uiOutput(outputId =  ns("my_tooltip"))
  )
}

and below is the corresponding server-side function,

# Server function to generate and download plot
MA_sroc_plot_server <- function(id, 
                           data,
                           draws) {
  moduleServer(
    id,
    function(input, output, session) {

    plot_object <- reactive({
                                 # code to produce ggplot here                          
           })

      # Output ggplot object
      output$plot <- renderPlot({  plot_object() })
      
      # Download ggplot object 
      output$plot_download <- downloadHandler(
        filename = function(){
          paste("plot.png")
        },
        content = function(file) { 
          {ggsave(file, plot_object())}
        } 
      )
      
     
      # Make reactive dataset to display over plot 
      dataset <- reactive({
        X <- req(data())
        X
      })

      # values to display on plot
      vals <- renderPrint({
        click <- {input$plot_click}

        y <- nearPoints(df = dataset(), click , xvar = "FPR", yvar = "Sensitivity" )
        req(nrow(y) != 0)
        y
      })
      
     # tooltip
      output$my_tooltip <- renderUI({
        ns <- session$ns

        y <- nearPoints(df = dataset(), ns("plot_click") , xvar = "FPR", yvar = "Sensitivity" )
        req(nrow(y) != 0)
        verbatimTextOutput(vals())
      })

      
    }
    
  )
}

Thanks.

P.S., apologies for not posting a minimal reproducible example (MRE). I only recently came across modules a few days ago so I am assuming I am just missing something obvious. If at a glance there appears to be nothing wrong with he code I posted, I can produce an MRE if it is necessary.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.