按下 actionButton 之前出错?

error before pushing actionButton?

我在按下操作按钮之前收到以下错误消息:

推送后一切正常Run Analysis!我错过了什么?

## app.R ##
library(shiny)
library(shinydashboard)
library(dplyr)
library(arm)
library(texreg)

header <- dashboardHeader()

sidebar <- dashboardSidebar(column(3, actionButton(inputId = "go", label = "Run Analysis!")))

body <- dashboardBody(fluidPage(fluidRow(
  box(
    title = "Regression Table",
    status = "primary",
    solidHeader = TRUE,
    width = 6,
    uiOutput("mybayesglm")
  )
)))



ui <- dashboardPage(header, sidebar, body)

server <- function(input, output) { 
  results <- reactiveValues()

  observeEvent(input$go, {
    # Gen fake data
    N<-1000
    df1 <- data.frame(v1=sample(c(0,1),N,replace = T),
                      v2=sample(c(0,1),N,replace = T),
                      Treatment=sample(c("A", "B", "C"), N, replace = T),
                      noise=rnorm(N)) %>% 
      mutate(Y=0.5*v1-0.7*v2+2*I(Treatment=="B")+3*I(Treatment=="C")+noise)
    # Run regression
    mybayesglm <- bayesglm(data = df1, formula = Y~Treatment+v1+v2)
    #ouput results in a reactive list
    results[[as.character(length(names(results)) + 1)]] <- mybayesglm
    return(results)
  }) #<-end observeEvent

  output$mybayesglm <- renderUI({
    HTML(
      htmlreg(reactiveValuesToList(results), ci.force = TRUE, ci.force.level = .95, caption = "")
    )
  })
  }

shinyApp(ui, server)

这样就可以了:

## app.R ##
library(shiny)
library(shinydashboard)
library(dplyr)
library(arm)
library(texreg)

header <- dashboardHeader()

sidebar <- dashboardSidebar(column(3, actionButton(inputId = "go", label = "Run Analysis!")))

body <- dashboardBody(fluidPage(fluidRow(
  box(
    title = "Regression Table",
    status = "primary",
    solidHeader = TRUE,
    width = 6,
    uiOutput("mybayesglm")
  )
)))



ui <- dashboardPage(header, sidebar, body)

server <- function(input, output) { 
  results <- reactiveValues()

  observeEvent(input$go, {
    # Gen fake data
    N<-1000
    df1 <- data.frame(v1=sample(c(0,1),N,replace = T),
                      v2=sample(c(0,1),N,replace = T),
                      Treatment=sample(c("A", "B", "C"), N, replace = T),
                      noise=rnorm(N)) %>% 
      mutate(Y=0.5*v1-0.7*v2+2*I(Treatment=="B")+3*I(Treatment=="C")+noise)
    # Run regression
    mybayesglm <- bayesglm(data = df1, formula = Y~Treatment+v1+v2)
    #ouput results in a reactive list
    results[[as.character(length(names(results)) + 1)]] <- mybayesglm
    return(results)
  }) #<-end observeEvent

  output$mybayesglm <- renderUI({
    if(input$go==0)
      return()
    else
    HTML(
      htmlreg(reactiveValuesToList(results), ci.force = TRUE, ci.force.level = .95, caption = "")
    )
  })
}

shinyApp(ui, server)