我正在try 用R构建一个表单,一旦单击表单末尾的操作按钮,它将用于填充一个表.我还没有弄明白的是如何在表单中提取数据并将其添加到表中的新行.现在,它只是用表单中的任何内容不断更新第一行.我在这里复制了代码的一个简单版本:


    #ui.r
    
    library(shiny)
    
    shinyUI(fluidPage(
      # Application title
      titlePanel("Test App"),
      
      sidebarPanel(
        numericInput("x", "Enter Value of X", 1),
        numericInput("y", "Enter Value of Y", 1),
        actionButton("add_data", "Add Data", width="100%")
      ),
      mainPanel(
        tableOutput("xy_Table")
      )
    )
    )

    #server.R

    library(shiny)
    library(tidyverse)
    
    shinyServer(function(input, output) {
    
      x <- vector("numeric")
      y <- vector("numeric")
      xyTable <- tibble(x, y)
      e <- reactive(input$x)
      f <- reactive(input$y)
      
      eventReactive(input$add_data, {
        xyTable %>% add_row(x=e(), y=f())
      })
      
      output$xy_Table <- renderTable({
        xyTable
      })
    })

非常感谢你的帮助.

推荐答案

为了更新输出,您需要使用react 式xyTable.而且

library(shiny)
library(tidyverse)

ui <- fluidPage(
  sidebarPanel(
    numericInput("x", "Enter Value of X", 1),
    numericInput("y", "Enter Value of Y", 1),
    actionButton("add_data", "Add Data", width = "100%")
  ),
  mainPanel(
    tableOutput("xy_Table")
  )
)

server <- function(input, output, session) {
  xyTable <- reactiveVal(
    tibble(x = numeric(), y = numeric())
  )

  observeEvent(input$add_data, {
    xyTable() %>%
      add_row(
        x = input$x,
        y = input$y,
      ) %>%
      xyTable()
  })

  output$xy_Table <- renderTable(xyTable())
}

shinyApp(ui, server)

R相关问答推荐

基于不同组的列的相关性

如何写一个R函数来旋转最后n分钟?

即使硬币没有被抛出,也要保持对其的跟踪

在RStudio中堆叠条形图和折线图

无法正确设置动态创建的Quarto标注的格式

R中1到n_1,2到n_2,…,n到n_n的所有组合都是列表中的向量?

使用RSelenium在R中抓取Reddit时捕获多个标签

如何从向量构造一系列双边公式

如何移除GGPlot中超出与面相交的任何格网像元

将多个列合并为一个列的有效方法是什么?

在不对R中的变量分组的情况下取两行的平均值

Conditional documentr::R中数据帧的summarize()

roxygen2正在处理太多的文件

如何为包创建自定义roxygen2标签?

R dplyr::带有名称注入(LHS of:=)的函数,稍后在:=的RHS上引用

在不带max()的data.table中按组查找最后一个元素

在一个multiplot中以非对称的方式在R中绘制多个图

如何在基数R中根据矩阵散点图中的因子给数据上色?

获取列位置

我应该如何解决Raster程序包中未对齐的色条记号?