简体   繁体   English

R shinyjs 禁用 function 在从另一个模块获取输入的模块中不起作用

[英]R shinyjs disable function not working in module that takes input from another module

Below code is a minimum example of what I'm building in a larger app and I can't figure out why the textInput in output_module.R is not disabled.下面的代码是我在大型应用程序中构建的最小示例,我无法弄清楚为什么output_module.R中的textInput未被禁用。 Would be very grateful if anyone can help!如果有人可以提供帮助,将不胜感激!

app.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 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 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"))
      
    })
  }

This was resolved thanks to @Limey.这要感谢@Limey 解决。 Here is the correct code for the module that was edited.这是已编辑模块的正确代码。

output_module.R 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.
      
    })
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用来自 Shiny 模块的数字输入值作为用户定义的 function 的输入,并使用 function 中的 output 作为另一个模块的输入 - Using value of numeric input from Shiny module as input for user defined function and using output of that function as input in another module R闪亮的observeEvent在模块的功能中不起作用 - R shiny observeEvent not working in function in module Shinyjs:[add | remove]类在模块中不起作用 - Shinyjs: [add|remove]Class does not work in a module 如何在另一个输入模块中访问 R Shiny 输入(上传)文件? - How to access R Shiny Input(uploaded) file in another input module? 启用/禁用不使用 flexdashboard+shinyjs - Enable/disable not working with flexdashboard+shinyjs R Shinyjs Shinydashboard 框在radionButtons 输入上展开 - R shinyjs shinydashboard box uncollapse on radionButtons input 根据 Shiny 应用程序中模块的输入禁用 UI 中的按钮 - Disable button in UI based on input from module in Shiny app 如何在另一个发光模块中调用发光模块(一个模块到另一个模块的响应函数) - how to call a shiny module in another shiny module (reactive function from one module to the other) 无法从 R Shiny UI 模块中访问输入? - Impossible to access input from within R Shiny UI module? 将renderUI输入从一个Shiny模块传递到另一个模块 - pass renderUI input from one Shiny module to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM