Replies: 11 comments 1 reply
-
"Woaw Colin what a brilliant idea, how lucky am I to work with a talented mind like yours. |
Beta Was this translation helpful? Give feedback.
-
This seems like the right answer to me (and is how I've been writing my shiny 1.5 experiments). I see the moduleServer version as the one you'd export, so users can just use your module without anything fancy, but then the core function is internal and does the heavy lifting. |
Beta Was this translation helpful? Give feedback.
-
I agree with Jon--this looks great, Colin! Two reasons for me: (1) The extra layer of indentation in the new 1.5 version has been a bit annoying for me, since I can't fit as much in each line. So, a name_server_core pattern fixes that. (2) I think this also makes for an easier transition. Basically, if users still want to use the callModule pattern for whatever reason, they can--they'll just call name_server_core instead. |
Beta Was this translation helpful? Give feedback.
-
Just a quick question, with this approach, does additional arguments have to be added manually in both the core function and the inner module? E.g.
|
Beta Was this translation helpful? Give feedback.
-
@KasperThystrup Yes, this is indeed my current issue with this format. I think that for now we will stick with the one suggested by the |
Beta Was this translation helpful? Give feedback.
-
Using the |
Beta Was this translation helpful? Give feedback.
-
That's indeed what I suggested in rstudio/shiny#3008, but I'm not sure it's gonna be there soon unfortunately :/ |
Beta Was this translation helpful? Give feedback.
-
I'll leave this discussion open for now. The new add_module version add the structure for the recommended We'll see how it evolves. |
Beta Was this translation helpful? Give feedback.
-
I agree with what Joe Cheng said in the other thread over at name_ui <- function(id){
ns <- NS(id)
tagList(
# ...
)
}
name_server <- function(id) {
moduleServer(id, function(input, output, session) {
data <- reactive({
# ...
})
# ...
})
} The I really don't mind the 1 extra indentation (but then I typically only use a double space so my indents are quite small) and the extra complexity of having to duplicate arguments is not worth it to me. That being said, I thought I'd shoot myself in the foot and point out that there is a way to do what you want without any update from So the following works and only requires the arguments in the name server: name_server_core <- function(input, output, session) {
observeEvent( input$go , {
print("hey")
})
}
name_server <- function(id, argument_A, argument_B, stop_arguing) {
environment(name_server_core) <- environment()
moduleServer(id, name_server_core)
} I am not sure this is any better as I find it highly counter-intuitive to add arguments in the |
Beta Was this translation helpful? Give feedback.
-
One slightly more complex approach would be to draw inspiration from e.g. Making a
This might be a bit more messy approach, and does require some serious rearrangement in existing functions. I don't know whether I would recommend this, yet I wanted to throw it out there! :-) |
Beta Was this translation helpful? Give feedback.
-
Are there still plans to support |
Beta Was this translation helpful? Give feedback.
-
Based on the recent changes in shiny (see also #455), the recommended way to write module is now with
moduleServer()
.Here is the change in the way to write it:
which is now written:
I'm a little against about writing the module code this way, as it creates a complex, nested structure.
I think we could make things clearer by using this pattern:
It will mean we need 3 functions, but it seems to me easier to write and understand: we still write server functions the way we use to, and it makes converting old code easier.
And we would actually only be working with two functions, the last one will not need to change regularly (expect when changing the server function arguments).
I think this should be the default skeleton.
What do y'all think about this?
Beta Was this translation helpful? Give feedback.
All reactions