【发布时间】:2014-04-24 23:49:36
【问题描述】:
关注 alexwhan 的“向 Shiny 中的反应式表添加值”线程:
有没有办法避免打印第一个空行?
我尝试将values$df 修改为values$df(-(1:1),),但这会打印表中索引为“2”的第一行。
谢谢!
【问题讨论】:
关注 alexwhan 的“向 Shiny 中的反应式表添加值”线程:
有没有办法避免打印第一个空行?
我尝试将values$df 修改为values$df(-(1:1),),但这会打印表中索引为“2”的第一行。
谢谢!
【问题讨论】:
我的解决方案是不创建第一行,而是创建一个带有空行的 data.frame。顺便说一句,使用索引似乎比rbind() 更好:
library(shiny)
runApp(list(
ui=pageWithSidebar(headerPanel("Adding entries to table"),
sidebarPanel(textInput("text1", "Column 1"),
textInput("text2", "Column 2"),
actionButton("update", "Update Table")),
mainPanel(tableOutput("table1"))),
server=function(input, output, session) {
values <- reactiveValues()
#Create 0 row data.frame
values$df <- data.frame(Column1 = numeric(0), Column2 = numeric(0))
newEntry <- observe({
if(input$update > 0) {
isolate(values$df[nrow(values$df) + 1,] <- c(input$text1, input$text2))
}
})
output$table1 <- renderTable({values$df})
}))
【讨论】: