I'm trying to create a plot in Shiny, but it is not working. It is blank.
I think it is because lavaanPlot
uses DiagrammeR
svg graphics.
Here's the code
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)
I'm getting this error sometimes:
Error: trying to get slot "ParTable" from an object (class "reactiveExpr") that is not an S4 object