首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >修复初始shinyr应用程序加载的selectInput错误

修复初始shinyr应用程序加载的selectInput错误
EN

Stack Overflow用户
提问于 2016-11-09 15:28:49
回答 1查看 557关注 0票数 1

当运行下面这个闪亮的应用程序时,我最初得到的是错误-- invalid type/length (symbol/0) in vector allocation。然而,一旦我点击“提交”应用程序的功能,如预期。

有没有办法避免这个启动错误,并让它从一开始就正常工作?

代码语言:javascript
运行
复制
plot_and_summary <- function(dat, col){
  summary <- dat %>% summarize_(mean = interp(~mean(x), x = as.name(col)),
                                sd = interp(~sd(x), x = as.name(col)))
  plot <- ggplot(dat, aes_string(x = col)) + geom_histogram()
  return(list(summary = summary, plot = plot))
} 


library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(
  titlePanel(""),
  sidebarLayout(
    sidebarPanel(
      uiOutput("column_select"),
      submitButton("Submit")
    ),
    mainPanel(
      tableOutput("summary"),
      plotOutput("plot")
      )
  )

)

# Define server logic required to draw a histogram
server <- function(input, output){
  dat <- reactive({iris})


  output$column_select <- renderUI({selectInput("col", label = "select column", choices = as.list(names(dat())))})



  pas <- reactive({plot_and_summary(dat(), input$col)})
  output$plot <- renderPlot({pas()$plot})
  output$summary <- renderTable({pas()$summary})


}


shinyApp(ui = ui, server = server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-09 17:29:16

req函数应该可以解决您的问题

http://shiny.rstudio.com/reference/shiny/latest/req.html

代码语言:javascript
运行
复制
pas <- reactive({plot_and_summary(dat(), req(input$col))})
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40510536

复制
相关文章

相似问题

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