简体   繁体   English

如何在闪亮的不同选项卡面板上使用相同的输出绑定

[英]How to use the same output binding on different tab panels in shiny

In my server.R file, I have a reactive called myNet which generates a visNetwork . 在我的server.R文件中,我有一个名为myNet ,它生成一个visNetwork In my ui.R , I have multiple tab panels that ideally will have different input widgets that effect the visNetwork . 在我的ui.R ,我有多个选项卡面板, 理想情况下会有不同的输入窗口小部件影响visNetwork

Is it possible to re-use the same binding? 是否可以重复使用相同的绑定?

Currently, when I try to run the code similar to below, I receive an error: Uncaught Duplicate binding for ID vis . 目前,当我尝试运行类似于下面的代码时,我收到一个错误: Uncaught Duplicate binding for ID vis


Snippet of server.R 服务器片段server.R

  myNet <- reactive({
    nodes <- df_nodes
    edges <- df_edges        
    visNetwork(nodes, edges, height = '800px')
  })

  output$vis <- renderVisNetwork(
    myNet()
  )

Snippet of ui.R ui.R片段

  ...

  tabPanel("First Panel",
    sidebarLayout(
      sidebarPanel(
        sliderInput("input1", "Title 1", 
                    min=1, max=10, value=1),
        sliderInput("input2", "Title 2",
                    min=1, max=10, value=1),
        sliderInput("input3", "Title 3",
                    min=1, max=10, value=1)
      ),
      mainPanel(
        visNetworkOutput("vis", height = '800px') # *** ISSUE HERE***
      )
    )
  ),
  tabPanel("Second Panel",
    sidebarLayout(
      sidebarPanel(
        sliderInput("input4", "Title 4", 
                    min=1, max=10, value=1),
        sliderInput("input5", "Title 5",
                    min=1, max=10, value=1),
      ),
      mainPanel(
        visNetworkOutput("vis", height = '800px') # *** ISSUE HERE***       
      )
    )
  ), ...

I ended up opening this GitHub issue . 我最终打开了这个GitHub问题 The consensus appears to be that the following is the best method: 共识似乎是以下是最好的方法:

output$vis_1 <- output$vis_2 <- renderVisNetwork(myNet())

Alternatively, as alluded to in the comments, you could use a not-so-DRY approach: 或者,正如评论中所提到的,您可以使用不那么干的方法:

output$vis_1 <- renderVisNetwork(myNet())
output$vis_2 <- renderVisNetwork(myNet())

Joe Cheng appropriately made the following comment on the GitHub issue: Joe Cheng对GitHub问题做了如下评论:

"Allowing multiple outputs to share the same ID would have a lot of gnarly side effects, it makes my head hurt to even think about what it would mean. For example, two Leaflet maps with the same ID--but they both have lots of state in the browser, and communicate that state back to the client. How can you make sense of that when they share the same ID? " “允许多个输出共享相同的ID会产生很多粗糙的副作用,甚至考虑它的含义会让我头疼。例如,两张具有相同ID的Leaflet地图 - 但它们都有很多在浏览器中显示状态,并将该状态传达给客户端。当他们共享相同的ID时,您怎么能理解它?

All said and told, I was able to ahieve the same behavior using the dynamic UI approach with a switch that toggles which controls are displayed to the user via uiOutput() (in the ui.R file) and output$ui <- renderUI({...}) (in the server.R file). 所有人都说,并且我能够使用动态UI方法同样的行为来切换通过uiOutput() (在ui.R文件中)向用户显示哪些控件,并output$ui <- renderUI({...}) (在server.R文件中)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM