【发布时间】:2020-07-31 20:50:48
【问题描述】:
我正在尝试在 Shiny 中初始化反应式 data.frame。我想我快到了,但它并没有像预期的那样工作。
下面是一个非常简单的应用程序,我将仅用于说明目的。本质上,表中的值应该根据滑块输入而改变。虽然他们似乎这样做了,但表输出看起来不像我会在 r 中看起来像 data.frame 表。与正常外观不同,它仅输出一列(标题为“数据”)。
我认为我还没有完全理解 reactive() 对象的工作原理,如果在如何初始化响应式对象中的表方面提供任何帮助,我将不胜感激。谢谢!
library(shiny)
ui <- fluidPage(
tableOutput("first"),
sliderInput("num","choose num",1,10,1)
)
server <- function(input, output, session) {
# t1 = (as.data.frame(forecast %>% filter(Date==Sys.Date()-21) %>% group_by(Resort,Date) %>% summarise(`Powder Total` = sum(Snow))))
# t1=t1[order(t1$`Powder Total`,decreasing=TRUE),][1:5,]
# output$first = renderTable({
# t1[1,]
# })
test = reactive({
d1 = as.data.frame(matrix(nrow=2,ncol = 2))
names(d1)=c("col1","col2")
d1$col1=input$num
d1$col2=input$num+1
})
output$first=renderTable({
test()
})
}
shinyApp(ui, server)
【问题讨论】:
标签: r dataframe shiny reactive