r闪亮的模块,从服务器返回的反应性表达未知

发布于 2025-02-11 17:08:07 字数 1092 浏览 2 评论 0原文

在我的“主应用程序”中,我想通过随附的闪亮模块来处理返回的的反应剂。我的问题是我找不到一种“抓住”返回反应性的方法。

当我尝试解决反应性时,会有一个错误消息: 警告:recturn_data中的错误:找不到函数“ reded_data”

是否有任何方法可以做到这一点?

require(shiny)

example_UI <- function(p_id) {
  actionButton(NS(p_id,"mergelist"), "mergelist")
}

example_Server <- function(p_id, p_list) {
  moduleServer(p_id, function(input, output, session) {
    observeEvent(input$mergelist, {
      return(reactive({
        rbind(data.frame("ID" = c(3, 5), "NAME" = c("lorem", "ipsum")), p_list())
      }))
    })
  })
}

example_App <- function() {
  global_list <- reactiveVal({ data.frame(ID = integer(), NAME = character()) })

  ui <- fluidPage(
    example_UI(p_id = "example"),
    verbatimTextOutput("rows")
  )

  server <- function(input, output, session) {
    returned_data <- example_Server(p_id = "example", p_list = global_list)
    output$rows <- renderText({
      nrow(returned_data())
    })
  }
  shinyApp(ui, server)
}

runApp(example_App())

In my "master app" i want to handle the reactives that are returned by included shiny modules. My problem is that I don't find a way to "catch" the returned reactive.

There is an error message when i try to resolve the reactive: Warning: Error in returned_data: could not find function "returned_data"

Is there any way to do this?

require(shiny)

example_UI <- function(p_id) {
  actionButton(NS(p_id,"mergelist"), "mergelist")
}

example_Server <- function(p_id, p_list) {
  moduleServer(p_id, function(input, output, session) {
    observeEvent(input$mergelist, {
      return(reactive({
        rbind(data.frame("ID" = c(3, 5), "NAME" = c("lorem", "ipsum")), p_list())
      }))
    })
  })
}

example_App <- function() {
  global_list <- reactiveVal({ data.frame(ID = integer(), NAME = character()) })

  ui <- fluidPage(
    example_UI(p_id = "example"),
    verbatimTextOutput("rows")
  )

  server <- function(input, output, session) {
    returned_data <- example_Server(p_id = "example", p_list = global_list)
    output$rows <- renderText({
      nrow(returned_data())
    })
  }
  shinyApp(ui, server)
}

runApp(example_App())

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我闹别瞎闹 2025-02-18 17:08:07

多亏了@limey,我发现了自己的错误,并能够解决问题。

  moduleServer(p_id, function(input, output, session) {
    
    retval <- reactiveVal()
    
    observeEvent(input$mergelist, {
      retval(...)
    })
    
    retval

  })

Thanks to @Limey I found my mistake and was able to solve the problem.

  moduleServer(p_id, function(input, output, session) {
    
    retval <- reactiveVal()
    
    observeEvent(input$mergelist, {
      retval(...)
    })
    
    retval

  })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文