R 闪亮模式下的树失真

R 闪亮模式下的树失真,r,shiny,bootstrap-modal,R,Shiny,Bootstrap Modal,当在一个闪亮的应用程序中的同一个modelDialog()中多次渲染时,CollapsableTreeSummary()的实例会失真。在多次渲染模态和树之后,会对树进行压缩,使其难以理解 例如,此代码显示一棵水平树,按部门表示一家人工公司的员工总数 已修改 库(闪亮) 图书馆(可折叠树) 选择1_data=data.frame( V1=c(代表(“公司”,3),“销售”), V2=c(“财务”、“营销”、“人力资源”、“销售”), V3=c(110,43,12243) ) 选择2_data=da

当在一个闪亮的应用程序中的同一个modelDialog()中多次渲染时,CollapsableTreeSummary()的实例会失真。在多次渲染模态和树之后,会对树进行压缩,使其难以理解

例如,此代码显示一棵水平树,按部门表示一家人工公司的员工总数

已修改

库(闪亮)
图书馆(可折叠树)
选择1_data=data.frame(
V1=c(代表(“公司”,3),“销售”),
V2=c(“财务”、“营销”、“人力资源”、“销售”),
V3=c(110,43,12243)
)
选择2_data=data.frame(
V1=c(代表(“公司”,3),“销售”,“IT”),
V2=c(“财务”、“营销”、“人力资源”、“销售”、“IT”),
V3=c(110,43,12243,22)
)
选择3_data=data.frame(
V1=c(代表(“公司”,3)、“销售”、“IT”、“管理”),
V2=c(“财务”、“营销”、“人力资源”、“销售”、“IT”、“管理”),
V3=c(110,43,12243,34,22)
)

ui我不知道为什么会发生这种情况,但是在
modalDialog()中显示ui(除了文本)的正确方法是创建一个函数来触发前面提到的modalUI。

因此,我刚刚将您的
可折叠树移出按钮的观察事件外部,并将
绘图模式()
包含在按钮的观察事件内部。
此函数将生成适当的UI

这是修改后的代码

library(shiny)
library(collapsibleTree)

df = data.frame(
  V1 = c(rep("Corporate",3),"Sales"),
  V2 = c("Finance","Marketing","HR","Sales"),
  V3 = c(110,43,12,243)
)

ui <- fluidPage(

  mainPanel(
    br(),
    actionButton("mainButton","Click me")
  )

)

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

  output$tree = renderCollapsibleTree({

    collapsibleTreeSummary(
      df,
      root="Fake Corporation",
      hierarchy=c("V1","V2"),
      zoomable=T,
      attribute="V3",
      nodeSize="V3",
      tooltip=T,
      linkLength=250,
      fontSize=12
    )

  })

  plotModal <- function(failed = FALSE) {
    modalDialog(
      title = NULL,
      size="l",
      easyClose=T,
      # Display the tree
      fluidPage(collapsibleTreeOutput("tree"))

    )
  }

  observeEvent(input$mainButton,{
    showModal(plotModal())
  })

}

shinyApp(ui,server)
库(闪亮)
图书馆(可折叠树)
df=data.frame(
V1=c(代表(“公司”,3),“销售”),
V2=c(“财务”、“营销”、“人力资源”、“销售”),
V3=c(110,43,12243)
)

当我在
renderUI({})
函数中而不是在
fluidPage()中渲染数据树时,ui问题已得到解决:


谢谢您的回复。但当我添加了三个单选按钮并通过选择其中一个来修改树数据时,问题仍然存在。您能否通过编辑您的问题提供一个可复制的示例?
library(shiny)
library(collapsibleTree)

df = data.frame(
  V1 = c(rep("Corporate",3),"Sales"),
  V2 = c("Finance","Marketing","HR","Sales"),
  V3 = c(110,43,12,243)
)

ui <- fluidPage(

  mainPanel(
    br(),
    actionButton("mainButton","Click me")
  )

)

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

  output$tree = renderCollapsibleTree({

    collapsibleTreeSummary(
      df,
      root="Fake Corporation",
      hierarchy=c("V1","V2"),
      zoomable=T,
      attribute="V3",
      nodeSize="V3",
      tooltip=T,
      linkLength=250,
      fontSize=12
    )

  })

  plotModal <- function(failed = FALSE) {
    modalDialog(
      title = NULL,
      size="l",
      easyClose=T,
      # Display the tree
      fluidPage(collapsibleTreeOutput("tree"))

    )
  }

  observeEvent(input$mainButton,{
    showModal(plotModal())
  })

}

shinyApp(ui,server)
 plotModal <- function(failed = FALSE) {
    modalDialog(
      title = NULL,
      size="l",
      easyClose=T,
      # Display the tree
      renderUI(collapsibleTreeOutput("tree"))

    )
  }