使用操作按钮更新 table

updating a table with action button

我正在尝试开发一个非常基本的闪亮应用程序。 ui脚本很简单

shinyUI(fluidPage(
  titlePanel("Drawing a Dice"),

  sidebarLayout(
    sidebarPanel(
      actionButton("action", label = "Draw"),
    ),

    mainPanel(
      textOutput("text1")
    )
  )
)) 

但我不确定如何着手做服务器。 R

我需要 server.R 执行以下操作:每次用户单击绘制时,它都会从 1:6 中抽取一个随机数并填充 10 元胞数组的第一个元胞。每次点击 done til 10,它都会重复这个工作。最终结果将是一个长度为 10 的向量,其随机数介于 1 到 6 之间。需要为用户提供通过单击完成退出的选项。但是我需要能够在关闭应用程序后检索最终的结果向量。 因此 server.R 需要以一步递增的方式执行以下操作

draw<-function(){
  Dice<-c(1:6)
  Mydraws<-numeric(10)
  for(i in 1:10){
    x<-sample(Dice,1,replace=TRUE)
    Mydraws[i]=x
  }
  Mydraws
}

因此,即使在用户通过单击完成退出后,我也应该能够获取 Mydraws 矢量(不包括在 ui.R 中)

我什至不知道它是否可能闪亮。

这是一种方法:

server.R

numbers <- list()

shinyServer(function(input, output) 
{
    output$array <- renderText({
        # the presence of input$action will cause this to be evaluated each time the button is clicked
        # the value gets incremented each time you click it, which is why we use it as the index of the list

        random_number <- sample(1:6,1)

        # add to the global variable
        numbers[input$action] <<- random_number

        return(random_number)
    })
})