首页 > 解决方案 > 如何在闪亮 (R) 中绘制流程图 (bupar)?

问题描述

在我的应用程序中,我想上传一个本地 csv 文件(事件日志),显示数据表,然后使用 csv 文件(bupar)中的数据创建一个流程图。在普通的 R 脚本中,进程图的创建工作正常。但是,如何通过按下按钮“createDiagram”按钮在闪亮的应用程序中绘制流程图(在 DataTables 下方)?提前致谢!

代码下方:

library(shiny)


ui <- fluidPage(

  titlePanel("Visualization"),

  sidebarLayout(

    sidebarPanel(

      fileInput("file1", "Choose a File:",
                multiple = FALSE,
                accept = c("text/csv",
                           "text/comma-separated-values,text/plain",
                           ".csv")),

      tags$hr(),

      actionButton("createDiagram","Create a Process Diagram"),

      tags$hr()

    ),

    mainPanel(
      tableOutput("contents"),
      plotOutput("plot")
    )
  )
)

server <- function(input, output) {

  output$contents <- renderTable({

    req(input$file1)

    tryCatch(
      {
        inputData <- read.csv2(input$file1$datapath)
      },
      error = function(e) {
        stop(safeError(e))
      }
    )
  })
}


# Create Shiny app ----
shinyApp(ui, server)

标签: rshiny

解决方案


processmap() 输出一个 dgr_graph 对象。这些可以在闪亮的应用程序中呈现

library(DiagrammeR)
grVizOutput(outputId = "process")

output$process <-  renderGrViz({
  plot <- process_map(eventlog, render = F)
  render_graph(plot)
})

推荐阅读