Skip to content

Instantly share code, notes, and snippets.

@ismirsehregal
Created November 23, 2022 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismirsehregal/1ca6c17879e5bb91610d3fd31a7ffe24 to your computer and use it in GitHub Desktop.
Save ismirsehregal/1ca6c17879e5bb91610d3fd31a7ffe24 to your computer and use it in GitHub Desktop.
Update reactiveVal based on upstream reactive expressions
# https://stackoverflow.com/questions/74525623/follow-up-delete-rows-from-data-frames-in-shiny-using-datatable-server-side
library(shiny)
library(DT)
ui <- fluidPage(
sliderInput(
inputId = "sl1",
label = "sl1",
min = 1,
max = 10,
value = c(1,10)
),
sliderInput(
inputId = "sl2",
label = "sl2",
min = 1,
max = 10,
value = c(1,10)
),
sliderInput(
inputId = "sl3",
label = "sl3",
min = 1,
max = 10,
value = c(1,10)
),
DTOutput("table")
)
server <- function(input, output, session) {
r1 <- reactive({input$sl1*2})
r2 <- reactive({input$sl2*3})
r3 <- reactive({input$sl3*4})
expanded_table <- reactiveVal()
observe({
expanded_table(expand.grid(r1(), r2(), r3()))
})
result_table <- reactive({
expanded_table()*10
})
output$table <- renderDT({
result_table()
}, server = FALSE)
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment