Created
May 19, 2021 14:25
-
-
Save MayaGans/8fb2d177a2790b82173c700f3b7d390f to your computer and use it in GitHub Desktop.
Hacking Bookmarking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| # stealing this from the shiny source code for updateXInput | |
| dropNulls <- function(x) { | |
| x[!vapply(x, is.null, FUN.VALUE=logical(1))] | |
| } | |
| ui <- function() { | |
| tagList( | |
| sliderInput("test1", "Slider", value = 2, min = -2, max = 2, step = 0.01), | |
| textInput("test2", "Text", value = "Test"), | |
| actionButton("change", "CHANGE") | |
| ) | |
| } | |
| server <- function(input, output, session) { | |
| # pretend this is a list read in from a json object | |
| # from a database | |
| myinputlist <- list( | |
| test1 = 1, | |
| test2 = "Hello" | |
| ) | |
| observeEvent(input$change, { | |
| # store all the new values within message | |
| # message <- drupNulls(list(value=1)) | |
| messages <- purrr::map(myinputlist, ~dropNulls(list(value=.[[1]]))) | |
| # then send them as new values | |
| purrr::imap(messages, ~session$sendInputMessage(.y, dropNulls(list(value=.x[[1]])))) | |
| # session$sendInputMessage("test1", message) | |
| }) | |
| } | |
| shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment