我有一个Excel数据集,我想在上传后操作它。假设在这种情况下,我想添加一个newcolumn <- 3
,我该如何解决这个问题?非常感谢。
用户界面
library(shiny)
ui <- fluidPage(titlePanel("daily data manipulation"),
sidebarLayout(sidebarPanel(
fileInput('file1', 'Choose xlsx file',
accept = c(".xlsx"))
),
mainPanel(tableOutput(outputId = "mytable")
)))
server.r
server <- function(input, output) {
data <- reactive({
inFile <- input$file1
if(!is.null(inFile)) {
readxl::read_excel(inFile$datapath)
}
})
dat <- data()
output$mytable <- renderTable({
dat$newcolumn <- 3
})
}
1条答案
按热度按时间mzaanser1#
React式表达式只能在React式上下文中使用,因此
dat <- data()
应该移动到renderTable
内部。此外,在添加新列之前检查reactive值是否为null可确保在用户上传excel文件之前不会呈现新列。