Shiny Module que llama a un conjunto de datos reactivos en el servidor Shiny principal

Estoy buscando portar algunas aplicaciones Shiny anteriores para usar Módulos Shiny, pero tengo problemas para intentar portar mis expresiones reactivas.

De acuerdo con ladocumentación:

El objetivo no es evitar que los módulos interactúen con sus aplicaciones que los contienen, sino más bien, hacer explícitas estas interacciones. Si un módulo necesita usar una expresión reactiva, tome la expresión reactiva como un parámetro de función.

Tengo expresiones reactivas existentes que importan datos de API, etc., que me gustaría transmitir, pero parece que no puedo encontrar la sintaxis. Si modifico el dadoEjemplo de módulo brillante a continuación puedo llegar al mismo problema.

¿Alguien podría modificar lo siguiente para que pueda pasar elcar_data() datos reactivos en el módulo? He probado casi todas las combinaciones deisolate ycar_data/car_data() Puedo pensar y estoy perplejo :)

Preferiría no tener que llamar a los datos dentro del módulo en sí, ya que en mi caso estoy tratando de generalizar una función ETL aplicable a muchos conjuntos de datos.

library(shiny)
library(ggplot2)

linkedScatterUI <- function(id) {
  ns <- NS(id)

  fluidRow(
    column(6, plotOutput(ns("plot1"), brush = ns("brush"))),
    column(6, plotOutput(ns("plot2"), brush = ns("brush")))
  )
}

linkedScatter <- function(input, output, session, data, left, right) {
  # Yields the data frame with an additional column "selected_"
  # that indicates whether that observation is brushed
  dataWithSelection <- reactive({
    brushedPoints(data(), input$brush, allRows = TRUE)
  })

  output$plot1 <- renderPlot({
    scatterPlot(dataWithSelection(), left())
  })

  output$plot2 <- renderPlot({
    scatterPlot(dataWithSelection(), right())
  })

  return(dataWithSelection)
}

scatterPlot <- function(data, cols) {
  ggplot(data, aes_string(x = cols[1], y = cols[2])) +
    geom_point(aes(color = selected_)) +
    scale_color_manual(values = c("black", "#66D65C"), guide = FALSE)
}

ui <- fixedPage(
  h2("Module example"),
  linkedScatterUI("scatters"),
  textOutput("summary")
)

server <- function(input, output, session) {

  ### My modification 
  ### making the reactive outside of module call
  car_data <- reactive({
    mpg
    })

  ## This doesn't work
  ## What is the syntax for being able to call car_data()?
  df <- callModule(linkedScatter, "scatters", car_data(),
                   left = reactive(c("cty", "hwy")),
                   right = reactive(c("drv", "hwy"))
  )

  output$summary <- renderText({
    sprintf("%d observation(s) selected", nrow(dplyr::filter(df(), selected_)))
  })
}

shinyApp(ui, server)

Respuestas a la pregunta(2)

Su respuesta a la pregunta