![](/img/trans.png)
[英]Another Follow up to “add values to a reactive table in Shiny” when we already have a dataframe
[英]Follow up to “add values to a reactive table in Shiny”
跟随alexwhan的“向Shiny中的值添加值到反应表”线程:
有没有办法避免打印第一个空行?
我尝试将values$df
修改为values$df(-(1:1),)
但这将打印表中索引为“ 2”的第一行。
谢谢!
对我来说,解决方案是不创建第一行,而是创建一个空行的data.frame。 rbind()
,使用索引而不是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})
}))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.