-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] - Support reactives in addition to reactiveValues #162
Comments
|
Yes might be possible to support a Currently Victor |
I had a similar issue. One way to circumvent this is to resolve the reactive and assign the dataset to the global environment with
Not sure if its safe or preferred. I'd be interested to see alternative solutions. HTH! |
It's true that the current implementation using reactiveValues works, but I do also think that it's awkward/not intuitive. It would be more clear and more in-line with most of the other shiny extensions if instead there would be two separate variables "data" and "name" and both of them would take a reactive. This will also organically solve another issue: using one parameter to group together two parameters is also not a great practice. It will also solve #227 I'm usually extremely conservative with breaking API changes, but I feel strongly enough about this that I would even argue it's worth changing the |
An example of the difference it would make in code: Current: ui <- fluidPage(
selectInput("dataset", "dataset", c("iris", "mtcars")),
esquisse::esquisse_ui("test")
)
server <- function(input, output, session) {
rv <- reactiveValues(data = data.frame(), name = "")
observeEvent(input$dataset, {
rv$data <- get(input$dataset)
rv$name <- input$dataset
})
esquisse::esquisse_server("test", rv)
}
shinyApp(ui, server) Proposed: ui <- fluidPage(
selectInput("dataset", "dataset", c("iris", "mtcars")),
esquisse::esquisse_ui("test")
)
server <- function(input, output, session) {
data <- reactive({
get(input$dataset)
})
name <- reactive({
input$data
})
esquisse::esquisse_server("test", data = data, name = name)
}
shinyApp(ui, server) And it would also be nice to be able to do without reactive values: ui <- fluidPage(
esquisse::esquisse_ui("test")
)
server <- function(input, output, session) {
esquisse::esquisse_server("test", data = iris, name = "iris")
}
shinyApp(ui, server) |
Thanks to all for suggesting this evolution and to @kieran-mace for initiating it. library(esquisse)
library(shiny)
ui <- fluidPage(
esquisse_ui("test")
)
server <- function(input, output, session) {
## with reactivalues
# rv <- reactiveValues(data = iris, name = "iris")
# esquisse_server("test", rv, import_from = NULL)
## with reactive()
esquisse_server("test", reactive(iris), name = reactive("iris"), import_from = NULL)
## with data.frame
# esquisse_server("test", iris, name = "iris")
}
shinyApp(ui, server) |
In addition to this functionality, that uses reactiveValues and observeEvent:
also support the use of reactives:
according to the developer of shiny
reactive
is far preferred over the combination ofreactiveValue
+observeEvent
The text was updated successfully, but these errors were encountered: