首页 > 解决方案 > R Shiny:从表输入创建和输出新表

问题描述

这是原始问题的延续。

我尝试做的是从输入创建一个新表并将该新表打印为输出。

我也想从输入中提取列来创建其他几个表。

我的代码给出了错误:赋值左侧无效(NULL):

ui <- fluidPage(

 headerPanel("title"),

  sidebarLayout(

sidebarPanel(

  h4("header"),
  tags$hr(),

      fileInput("file3", "description",
                multiple = TRUE,
                accept = c("text/csv",
                           "text/comma-separated-values,text/plain",
                           ".csv",".txt")),

  tags$hr(),

  width = 6
),

mainPanel(

  tableOutput("contents3"),

  width = 6

)
  )
)

server <- function(input, output) {


# input table:

  implop <- eventReactive(input$file3,{
    read.csv(input$file3$datapath,
                sep = input$sep)
  })  

# create new table:

    ip.lzb <- reactive ({ data.frame(cf=rep(0,21))

    ip.lzb()[11,] <- sum(implop()[ 1,2])
    ip.lzb()[12,] <- sum(implop()[ 2,2])
    ip.lzb()[13,] <- sum(implop()[ 3,2])
    ip.lzb()[14,] <- sum(implop()[ 4,2])
    ip.lzb()[15,] <- sum(implop()[ 5,2])
    ip.lzb()[16,] <- sum(implop()[ 6,2])
    ip.lzb()[17,] <- sum(implop()[7:9,2])
    ip.lzb()[18,] <- sum(implop()[10:12,2])
    ip.lzb()[19,] <- sum(implop()[13:24,2])
    ip.lzb()[20,] <- sum(implop()[25:60,2])
    ip.lzb()[21,] <- sum(implop()[61:120,2])

    rownames(ip.lzb()) <- rnames # predefined

    ip.lzb()[21,] <- ip.lzb()[21,] - sum(ip.lzb()[1:21,])

})       


# return new table:

  output$contents3 <- renderTable({

    ip.lzb()

  })

}

shinyApp(ui, server)

标签: rinputshinyoutput

解决方案


推荐阅读