R shiny js функция отключения не работает в модуле, который принимает входные данные от другого модуля - PullRequest
0 голосов
/ 06 августа 2020

Ниже приведен минимальный пример того, что я создаю в большом приложении, и я не могу понять, почему textInput в output_module.R не отключен. Был бы очень признателен, если кто-нибудь сможет помочь!

app.R

library(shiny)
library(shinyjs)

# Define UI
ui <- fluidPage(
    
    useShinyjs(),

    # Application title
    titlePanel("Demo"),

    # Sidebar 
    sidebarLayout(
        sidebarPanel(
            input_module_ui("input")
        ),

        mainPanel(
            output_module_ui("output")
        )
    )
)

# Define server logic 
server <- function(input, output, session) {
    
    callModule(input_module_server, "input")
    res <- callModule(input_module_server, "input")
    
    callModule(output_module_server, "output", res)
    
}

# Run the application 
shinyApp(ui = ui, server = server)

input_module.R

#Define ui
input_module_ui <- function(id) {
  ns <- NS(id)
  
  tagList(
    textInput(
      inputId = ns("input"),
      label = "Input:",
      value = "A"
      )
    )
}

#Define server logic 
input_module_server <- function(input, output, session) {
  
  #List of things to return for use in other modules
  return(input)
  
}

output_module.R

#Define ui
output_module_ui <- function(id){
  ns <- NS(id)

  tagList(
        textInput(inputId = ns("output"),
                     label = "Output:", 
                     value = ""
                  )
      )
}

#Define server logic 
output_module_server <-
  function(input,
           output,
           session,
           module_input) {

    observe({
      
      output <- module_input$input
      updateTextInput(session, "output", value = output)
      disable(id = session$ns("output"))
      
    })
  }

1 Ответ

0 голосов
/ 06 августа 2020

Эта проблема была решена благодаря @Limey. Вот правильный код для редактируемого модуля.

output_module.R

#Define ui
output_module_ui <- function(id){
  ns <- NS(id)

  tagList(
        textInput(inputId = ns("output"),
                     label = "Output:", 
                     value = ""
                  )
      )
}

#Define server logic 
output_module_server <-
  function(input,
           output,
           session,
           module_input) {

    observe({
      
      output <- module_input$input
      updateTextInput(session, "output", value = output)
      disable(id = "output") #This line was edited to resolve the issue.
      
    })
  }
...