Skip to content
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

Making runcode work inside Shiny modules #185

Merged
merged 5 commits into from
Jul 18, 2019
Merged

Conversation

mjhelf
Copy link
Contributor

@mjhelf mjhelf commented Jun 3, 2019

Hi @daattali ,
these are the changes as discussed in #184 ...

The id argument is used in an unusual way here (because the enclosing module UI needs to be passed, instead of creating an identifier for a UI element), so maybe the argument name should be changed to something else to make that clearer?

Let me know if this needs more testing or adjustments,

Best,
Max

Here is a minimal example, I wasn't sure whether it should be included in the documentation:

library(shiny)
library(shinyjs)
  
  ModuleEx <- function(input,output, session){
    runcodeServer()
  }
  
  ModuleExUI <- function(id){
    runcodeUI(id = id)
  }
  
  shinyApp(
    ui = fluidPage(
      useShinyjs(),  # Set up shinyjs
      ModuleExUI("Mod1")
    ),
    server = function(input, output) {
      callModule(ModuleEx, "Mod1")
    }
  )

And here is a more involved example that tests out the new possibilities:

  • calling runcode multiple times with different input types, inside and outside modules
  • accessing a reactive that is local to the module scope
library(shiny)
library(shinyjs)

  ModuleX <- function(input,output, session, 
                      aValue = reactive({})){
    runcodeServer()
    
  }
  
  ModuleXUI <- function(id, rcType = "text"){
    
    runcodeUI(code = "shinyjs::alert(aValue())",
              type = rcType,
              id = id)
    
    }
  
  
  shinyApp(
    ui = fluidPage(
      useShinyjs(),  # Set up shinyjs
      runcodeUI(code = "shinyjs::alert('Hello!')"),
      ModuleXUI("Mod1"),
      ModuleXUI("Mod2", rcType = "textarea"),
      ModuleXUI("Mod3", rcType = "ace")
      
      
    ),
    server = function(input, output) {
      runcodeServer()
      callModule(ModuleX, "Mod1", aValue = reactive({"This is Module#1"}))
      callModule(ModuleX, "Mod2", aValue = reactive({"This is Module#2"}))
      callModule(ModuleX, "Mod3", aValue = reactive({"This is Module#3"}))
      
    }
  )

@daattali
Copy link
Owner

daattali commented Jun 9, 2019

Looks good.

The span tag with id "runcode_errorMsg" also needs to be namespaced. The documentation should be capitalized and a bit more concise: "When used inside a shiny module, the module's id needs to be provided to \code{runcodeUI}. This argument should remain \code{NULL} when not used inside a module."

Also please bump the version in the DESCRIPTION , and add an item to the NEWS file

Update from daatali/shinyjs.. non-selectize select inputs could not be disabled; fixes daattali#186
@mjhelf
Copy link
Contributor Author

mjhelf commented Jul 18, 2019

Hi @daattali,
thanks for the feedback and sorry for the late response! I made changes according to your comments. Let me know if this is ok, thank you!

@daattali
Copy link
Owner

Looks great, thanks!

@daattali daattali merged commit 8426e21 into daattali:master Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants