使用 R shiny 中的输入值更新现有数据框

Update an existing dataframe with input values in R shiny

我正在开发一个闪亮的应用程序,我的用户会

  1. 输入一个整数值
  2. select 列表中的值

如果我的用户单击操作按钮,则必须使用输入的值更新现有数据框。

更新后的数据框应该显示在仪表盘正文中

library(shiny)
library(shinydashboard)

ui <-

dashboardPage(

    dashboardHeader(title = "title"),
    dashboardSidebar(

      selectInput("transaction_type", "select transaction type:", choices = 
  tranlist,selected = NULL),
  selectInput("entry_type", "select entry type", choices = entrylist),
  selectInput("sic", "select sic", choices = siclist),
  selectInput("markettype", "select market type", choices = marketlist),
  numericInput("qty", "enter quantity","",min = 0),
  numericInput("volume", "enter Total_amnt","",min = 0),

    ),
    dashboardBody(
      tableOutput("result")
    )
  )

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

pos <- reactive({

if(input$goButton >0){


 pos <- test[test$transaction_type == input$transaction_type && 
 test$entry_type == input$entry_type && test$qty == input$qty && 
 test$total_amount == input$volume && test$Average_Amnt == (input$volume/ 
 input$qty) && test$markettype == input$markettype && test$sic == input$sic]
 }  else{pos<- test}

return(pos)

})

output$result <- renderTable(pos())

}

单击操作按钮时,出现以下错误。

正在收听 http://127.0.0.1:7447 警告:<- 中的错误:无效的下标类型 'list' 堆栈跟踪(从最里面开始): 80 岁:xtable.data.frame 79: 78: do.call 77:origRenderFunc 76:输出$结果 1: 运行应用

请帮助我。提前致谢。

dput 输出低于

> dput(test)
structure(list(transaction_type = structure(4L, .Label = c("10", 
"11", "15", "20", "21", "25"), class = "factor"), entry_type = 
structure(13L, .Label = c("AMER", 
"ARC", "BOC", "CCD", "CIE", "CTX", "DISC", "EFT", "JCB", "MAST", 
"POP", "POS", "PPD", "RCK", "TEL", "VISA", "WEB"), class = "factor"), 
qty = 391L, total_amount = 10212.13, sic = structure(12L, .Label = c("4900", 
"5047", "6012", "6300", "6513", "7372", "7393", "7399", "7997", 
"8099", "8351", "8931", "8999", "9311", "9399"), class = "factor"), 
markettype = structure(1L, .Label = c("0", "1", "2", "3", 
"4"), class = "factor"), Average_Amnt = 26.1179795396419), .Names = 
c("transaction_type", 
"entry_type", "qty", "total_amount", "sic", "markettype", "Average_Amnt"
), row.names = c(NA, -1L), spec = structure(list(cols = structure(list(
location_id = structure(list(), class = c("collector_integer", 
"collector")), settle_date = structure(list(format = ""), .Names = "format", 
class = c("collector_date", 
"collector")), transaction_type = structure(list(), class = 
c("collector_integer", 
"collector")), entry_type = structure(list(), class = 
c("collector_character", 
"collector")), response_code = structure(list(), class = 
c("collector_character", 
"collector")), funding_type = structure(list(), class = 
c("collector_character", 
"collector")), qty = structure(list(), class = c("collector_integer", 
"collector")), service_fee = structure(list(), class = c("collector_skip", 
"collector")), total_amount = structure(list(), class = 
c("collector_double", 
"collector")), organization_id = structure(list(), class = 
c("collector_skip", 
"collector")), status = structure(list(), class = c("collector_character", 
"collector")), sic = structure(list(), class = c("collector_integer", 
"collector")), markettype = structure(list(), class = c("collector_integer", 
"collector")), isoid = structure(list(), class = c("collector_skip", 
"collector")), city = structure(list(), class = c("collector_skip", 
"collector")), StateProvince = structure(list(), class = 
c("collector_character", 
"collector")), postalcode = structure(list(), class = c("collector_skip", 
"collector")), CreateDate = structure(list(format = ""), .Names = "format", 
class = c("collector_datetime", 
"collector")), DeleteDate = structure(list(), class = c("collector_skip", 
"collector"))), .Names = c("location_id", "settle_date", 
"transaction_type", "entry_type", "response_code", "funding_type", 
"qty", "service_fee", "total_amount", "organization_id", "status", 
"sic", "markettype", "isoid", "city", "StateProvince", "postalcode", 
"CreateDate", "DeleteDate")), default = structure(list(), class = 
c("collector_guess", 
"collector"))), .Names = c("cols", "default"), class = "col_spec"), class = 
c("tbl_df", 
"tbl", "data.frame"))

以下代码对我有用。

library(shiny)
library(shinydashboard)

ui =   dashboardPage(

dashboardHeader(title = "title"),
dashboardSidebar(

  selectInput("transaction_type", "select transaction type:", choices = 
                tranlist),
  selectInput("entry_type", "select entry type", choices = entrylist),
  selectInput("sic", "select sic", choices = siclist),
  selectInput("markettype", "select market type", choices = marketlist),
  numericInput("qty", "enter quantity","",min = 0),
  numericInput("volume", "enter Total_amnt","",min = 0),
  actionButton("goButton","Enter")

),
dashboardBody(
  tableOutput("result")

)
)


#server.R

function(input, output,session){


pos <- eventReactive(input$goButton,{

if(input$goButton >0){


test[1:7] = c(input$transaction_type, input$entry_type, input$qty, 
input$volume , input$sic, input$markettype, input$volume/input$qty)
}  else{pos <- test}


 test

})

output$result <- renderTable(pos())

}