【发布时间】:2020-10-28 07:27:20
【问题描述】:
我正在尝试在 Shiny 中创建一个情节,但它不起作用。它是空白的。
我认为这是因为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
【问题讨论】:
-
你调用响应式对象就好像它们是函数一样。所以在你的
output$plot调用中,使用plot2()。 -
TyperWriter,在shiny.rstudio.com/tutorial/written-tutorial/lesson6中查找对
dataInput()的引用 -
我试过了,但在
output$plot内使用plot2()不起作用
标签: r ggplot2 plot shiny ggplotly