gpt4 book ai didi

r - 在 Module 中使用 Shiny 的 renderUI

转载 作者:行者123 更新时间:2023-12-01 22:51:34 24 4
gpt4 key购买 nike

这是我在 stackoverflow 上的第一个问题。我在 Shiny (1.0.5)中的模块和渲染UI有问题。

当我在

#### Main Part

ui <- bootstrapPage(
uiOutput("DynamicContent")
)

server <- function(input, output,session) {

S_A <- selectInput("S_A_Input" ,"Change Me for print message",choices=1:3 )

output$DynamicContent <- renderUI({
tagList(S_A)
})

observe({
print(input$S_A_Input)
})

}

shinyApp(ui = ui, server = server)

然后更改 selectInput 将导致更改 input$S_A_Input,因此将发生打印。没关系。

另一方面,如果我使用模块, input$S_A_Input 似乎不起作用:
### Module Part

Module_YYY_Server <- function(input, output, session){

S_A <- selectInput("S_A_Input" ,"Change Me for print message",choices=1:3 )

output$DynamicContent <- renderUI({
tagList(S_A)
})

observe({
print(input$S_A_Input)
})


}


Module_YYY_Ui <- function(id){

ns <- NS(id) # Creates Namespace

tagList(
uiOutput("DynamicContent" %>% ns)
)

}

然后调用模块。
#### Main Part

ui <- bootstrapPage(
Module_YYY_Ui("YYY")
)

server <- function(input, output,session) {
callModule(Module_YYY_Server,"YYY")
}

shinyApp(ui = ui, server = server)

我还没有找到解决这种行为的方法。

最佳答案

迟到了,但这是解决您的问题的另一种选择

session$ns("id")



这里的样子:
Module_YYY_Server <- function(input, output, session){

output$DynamicContent <- renderUI({
selectInput(session$ns("S_A_Input"), "Change Me for print message", choices = 1:3)
})

output$text <- renderText({
req(input$S_A_Input)
input$S_A_Input})
}


Module_YYY_Ui <- function(id){

ns <- NS(id) # Creates Namespace

tagList(
uiOutput(ns("DynamicContent")),
textOutput(ns("text"))
)
}


ui <- bootstrapPage(
Module_YYY_Ui("YYY")
)

server <- function(input, output,session) {
callModule(Module_YYY_Server,"YYY")
}

shinyApp(ui = ui, server = server)

这是基于示例 here

关于r - 在 Module 中使用 Shiny 的 renderUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46898569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com