我正试图创造一个闪亮的情节,但这是行不通的。它是空白的。我认为这是因为lavaanPlot使用DiagrammeR svg图形。
这是密码
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)我有时会犯这样的错误:
Error: trying to get slot "ParTable" from an object (class "reactiveExpr") that is not an S4 object 发布于 2020-07-12 01:16:32
我按照推荐的方式将这个绘图称为函数,然后使用了renderGrViz和grVizOutput,它起了作用。
我做了这个:
output$plot2 <- renderGrViz({
lavaanPlot(model = model())
})还有这个
grVizOutput("plot2", width = "50%", height = "100px")发布于 2020-07-08 01:42:32
输出图的ui.R码是
mainPanel(plotOutput("plot")
但是,在服务器中,R输出$绘图的名称是plot2,
output$plot <- renderPlot({plot2......
也许原因就在上面。
https://stackoverflow.com/questions/62785418
复制相似问题