反应价值-我在做什么错

时间:2018-07-28 04:38:26

标签: shiny reactive-programming

该应用程序旨在在单击操作按钮时显示summary_mod。但是我不断收到一个总结错误的错误。

summarized <- data.frame(id = 1:20, group = letters[1:4], TY_COMP = runif(20), LY_COMP = runif(20))

    library(shiny)

    ui <- fluidPage(
      verbatimTextOutput("text"),
      actionButton("btn", "Show the summarized")
    )

    server <- function(input, output){
              summarized <- reactive({summarized})
                observeEvent(input$btn,{ 
        summarized_mod <-summarized()$TY_COMP / summarized()$LY_COMP-1 } 
               })

      output$text <- renderPrint(summarized_mod())
    }

    shinyApp(ui, server)

1 个答案:

答案 0 :(得分:1)

dat <- data.frame(id = 1:20, 
                  group = letters[1:4], 
                  TY_COMP = runif(20), 
                  LY_COMP = runif(20))

library(shiny)

ui <- fluidPage(
  verbatimTextOutput("text"),
  actionButton("btn", "Show the summarized")
)

server <- function(input, output){
  # summarized <- reactive({summarized}) useless !
  summarized_mod <- eventReactive(input$btn, {
    dat$TY_COMP / dat$LY_COMP-1
  })
  output$text <- renderPrint(summarized_mod())
}

shinyApp(ui, server)