![](/img/trans.png)
[英]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 shinyjs disable function not working in module that takes input from another module
下面的代码是我在大型应用程序中构建的最小示例,我无法弄清楚为什么output_module.R
中的textInput
未被禁用。 如果有人可以提供帮助,将不胜感激!
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"))
})
}
这要感谢@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.
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.