Shiny modules : reactive values do not update

shiny

#1

Hi,

I am trying to use Shiny modules with a reactive value as parameter.

here is a simple example. The first plot is shown but when I click on the button to update the value of the reactive variable, the plot doesn't update.

Here is the code :

library(shiny)

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

fluidRow(
column(6, plotOutput(ns("plot1")))
)
}

linkedScatter <- function(input, output, session, data) {

dataWithSelection <- reactive({
data
})

output$plot1 <- renderPlot({
scatterPlot(data)
})

return(dataWithSelection)
}

scatterPlot <- function(data) {
plot(data)
}

ui <- fixedPage(
actionButton("test", "Increment"),
linkedScatterUI("scatters")
)

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

rv <- reactiveValues(test = 1)

callModule(linkedScatter, "scatters", rv$test)

observeEvent(input$test,{
rv$test <- -rv$test
})
}

shinyApp(ui, server)

I don't know how to make it work.

Thanks for your help


#3

Change your callModule function to:

callModule(linkedScatter, "scatters", data = reactive(rv$test))

Then reference the data argument inside your module as a reactive function: data()


#4

Thanks a lot !! It works perfectly :slight_smile:


#5

If your question's been answered, would you mind choosing a solution? (see FAQ below for how) It makes it a bit easier to visually navigate the site and see which questions still need help.

Thanks