问题描述
我知道这个问题已经被回答了多次,例如-plot.new has not been called yet,但是提供的解决方案对我没有用。
我的问题: 根据我需要的规范,我已经创建了一个用于创建系数图的函数。我目前已将回归输出保存在多个列表中,此功能需要一个输入列表的名称和起始元素,然后该函数从中选择图表的下6个元素(我的所有图表均显示7种不同的系数楷模)。功能如下-
library(haven)
library(dplyr)
library(tidyr)
library(stargazer)
library(lmtest)
library(sandwich)
library(glue)
library(dotwhisker)
library(broom)
library(shiny)
library(ggplot2)
library(shinydashboard)
library(rsconnect)
coeff_plot <- function(x,y) {
dwplot(list(x[[y]],x[[y+1]],x[[y+2]],x[[y+3]],x[[y+4]],x[[y+5]],x[[y+6]])),vline = geom_vline(xintercept = 0,colour = "grey60",linetype = 2),dot_args = list(size = 3.2)) +
xlab("Coefficient Estimate") +
theme(axis.text.x = element_text(size = rel(2)),axis.title.x = element_text(size = rel(2)),axis.text.y = element_text(size = rel(2)),legend.text = element_text(size = rel(1.5)),legend.title=element_blank())
}
接下来,我创建一个Shinyapp,其中有一个侧边栏,并根据侧边栏的输入显示不同的图。我的代码看起来像的示例-
ui = fluidPage(
sidebarPanel(selectInput("plots","Plots:",c("Plot type1","Plot type2","Plot type3")),width=3),mainPanel(
fluidRow(box(plotOutput("plot1"),width=15)),fluidRow(box(plotOutput("plot2"),width = 15)),fluidRow(box(plotOutput("plot3"),width = 15)))),server = function(input,output,session) {
output$plot1 <- renderPlot(if(input$plots == "Plot type1"){plot(coeff_plot(RegressionList1,1))}
else if(input$plots == "Plot type2"){plot(coeff_plot(RegressionList2,1))}
else {plot(coeff_plot(RegressionList3,1))})
output$plot2 <- renderPlot(if(input$plots == "Plot type1") {plot(coeff_plot(RegressionList4,1))}
else if(input$plots == "Plot type2"){plot(coeff_plot(RegressionList5,1)}
else {plot(coeff_plot(RegressionList6,1))})
output$plot3 <- renderPlot(if(input$plots == "Plot type1") {plot(coeff_plot(RegressionList7,1))}
else if(input$plots == "Plot type2"){plot(coeff_plot(RegressionList8,1))}
else {plot(coeff_plot(RegressionList9,1))})
}
# Create Shiny app ----
shinyApp(ui,server)
我的应用程序正在本地运行,但是当我发布所有文件时,出现以下错误:
应用程序无法启动(以代码1退出) value [3L]中的错误:尚未调用plot.new 调用:本地... tryCatch-> tryCatchList-> tryCatchOne->
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)