Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对RShiny中renderDataTable的列求和,并将结果存储在dataframe中供以后使用_R_Shiny_Shiny Reactivity - Fatal编程技术网

对RShiny中renderDataTable的列求和,并将结果存储在dataframe中供以后使用

对RShiny中renderDataTable的列求和,并将结果存储在dataframe中供以后使用,r,shiny,shiny-reactivity,R,Shiny,Shiny Reactivity,我不确定我在这里是否采取了正确的方法,但我已经创建了一个闪亮的应用程序,它可以按预期工作。 它从源中获取数据,并在用户点击执行按钮时将其显示为图表和表格 下面是reprex的代码。为了简单起见,删除了一些功能 library(shiny) ui <- fluidPage( actionButton("exe", "Run", style="color: #fff; background-color: #337ab7; border-color: #2

我不确定我在这里是否采取了正确的方法,但我已经创建了一个闪亮的应用程序,它可以按预期工作。 它从源中获取数据,并在用户点击执行按钮时将其显示为图表和表格

下面是reprex的代码。为了简单起见,删除了一些功能

library(shiny)

ui <- fluidPage(

  actionButton("exe", "Run", 
               style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),



  mainPanel(

    DT::dataTableOutput("datatable"),

  ))


server <- function(input, output, session) {

  ga_data <- eventReactive( input$exe, {

    the_date <- as.Date(c('2020-03-01','2020-03-02','2020-03-03','2020-03-04','2020-03-05' ))
    users <- c(346, 223, 167, 431, 293)
    employ.data <- data.frame(the_date, users)

  })

  output$datatable <- DT::renderDataTable({
    req(ga_data())
    ga_data <- ga_data()



    })



  }

  shinyApp(ui = ui, server = server)
库(闪亮)

ui当然,我们可以存储列“users”的总和,而不让表可见。请注意
的使用,您是否可以在以后使用它的地方定义它?例如,在渲染函数中,将其传递<代码>用户
library(shiny)

ui <- fluidPage(

  actionButton("exe", "Run", style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),

  mainPanel(plotOutput('myplot'))

)

server <- function(input, output, session) {

    ga_data <- eventReactive(input$exe, {

        the_date <- as.Date(c('2020-03-01', '2020-03-02', '2020-03-03', '2020-03-04', '2020-03-05'))
        users <- c(346, 223, 167, 431, 293)
        employ.data <- data.frame(the_date, users)

        #Store the sum of the column 'users' in a global variable, so we can use it anywhere later
        employ.data.sum <<- sum(employ.data$users, na.rm = TRUE)
        showNotification(paste("The sum of the column 'users' has been stored and is ready to use anywhere. Its", employ.data.sum))

        employ.data

    })

    output$myplot <- renderPlot({
        req(ga_data())
        plot(employ.data)
    })

}

shinyApp(ui = ui, server = server)