首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在R中显示来自其他包(如DiagrammeR )的绘图?

问如何在R中显示来自其他包(如DiagrammeR )的绘图?
EN

Stack Overflow用户
提问于 2020-07-07 23:40:53
回答 2查看 319关注 0票数 0

我正试图创造一个闪亮的情节,但这是行不通的。它是空白的。我认为这是因为lavaanPlot使用DiagrammeR svg图形。

这是密码

代码语言:javascript
复制
library(shiny)
library(lavaan)
library(lavaanPlot)

ui <- fluidPage(
    titlePanel("Text Input"),
    sidebarLayout(
        sidebarPanel(
            textAreaInput(inputId = "text1", 
                      label = "Syntax"), 
                      value = "Enter formula"),
        mainPanel(
           plotOutput("plot"),
           verbatimTextOutput("text1"),
           verbatimTextOutput("regout")
)))

server <- function(input, output, session) {
  formula <- reactive({
    tryCatch({
      input$text1
    }, error = function(e) NULL)
  })
  model <- reactive({
    if(!is.null(formula()))
    tryCatch({
        cfa(formula(), data = HolzingerSwineford1939)
      }, error = function(e) NULL)
    })
  results <- reactive({
    if(!is.null(model())){
      summary(model(), fit.measures = TRUE)
    }
  }) 
  output$regout <- renderPrint({
      results()
    })
  plot2 <- reactive({
      lavaanPlot(model = model)
    })
  output$plot <- renderPlot({
      plot2
    })
}
shinyApp(ui = ui, server = server)

我有时会犯这样的错误:

代码语言:javascript
复制
Error: trying to get slot "ParTable" from an object (class "reactiveExpr") that is not an S4 object 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-07-12 01:16:32

我按照推荐的方式将这个绘图称为函数,然后使用了renderGrViz和grVizOutput,它起了作用。

我做了这个:

代码语言:javascript
复制
output$plot2 <- renderGrViz({
      lavaanPlot(model = model())
    })

还有这个

代码语言:javascript
复制
grVizOutput("plot2", width = "50%", height = "100px")
票数 0
EN

Stack Overflow用户

发布于 2020-07-08 01:42:32

输出图的ui.R码是

mainPanel(plotOutput("plot")

但是,在服务器中,R输出$绘图的名称是plot2,

output$plot <- renderPlot({plot2......

也许原因就在上面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62785418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档