r-为什么shine不能检测到"observe"之外的"data.tree"操作



Shiny是否只能检测常见的R对象?如果是,它能观察到什么物体
例如,我尝试了许多选项,但都没有成功检测到闪亮中的data.tree变化
有人知道为什么会发生这种情况吗?

library(shiny)
library(data.tree)
data(acme)
ui <- fluidPage(
actionButton("go", "go" ),
tags$h2("text"),
verbatimTextOutput("text"),
tags$h2("text0"),
verbatimTextOutput("text0"),
tags$h2("text1"),
verbatimTextOutput("text1"),
tags$h2("text2"),
verbatimTextOutput("text2"),
tags$h2("text3"),
verbatimTextOutput("text3"),
tags$h2("text4"),
verbatimTextOutput("text4")
)
server <- function(input, output, session) {
anum <- reactiveValues(a = 0)
a <- reactiveValues(acme = acme, f = NULL)
b <- reactiveVal(acme)
cc <- reactive(a$acme)
observeEvent(input$go, {
z = sample(x = 1:100 , size = 1)
a$cach <<- a$acme$clone()
anum$a <<- anum$a + 1
a$acme$AddChild(paste0("New", z))
a$f <<-  a$acme
b(a$acme)
print("a$acme")
print(a$acme)
print("b()")
print(b())
})
### not working
output$text = renderPrint( print(a$f) )
output$text0 = renderPrint(print(b()))
output$text1 = renderPrint(print(cc()))
### working
observe({
print(identical(a$acme, a$cach))
output$text2 = renderPrint(print(b()))
})
### working
observe({
anum$a
output$text3 = renderPrint(print(a$acme))
})
### working
observeEvent(eventExpr =  anum$a, handlerExpr = {
output$text4 = renderPrint(print(a$acme))
})
}
shinyApp(ui, server)

原来添加:

a$f <- 0 #to force reaction
a$f <-  a$acme
a$acme <- 0 #to force reaction
a$acme <- a$f

"修复"了问题。

library(shiny)
library(data.tree)
data(acme)
ui <- fluidPage(
actionButton("go", "go" ),
verbatimTextOutput("text"),
verbatimTextOutput("text1"),
verbatimTextOutput("text2"),
verbatimTextOutput("text3"),
verbatimTextOutput("text4")

)
server <- function(input, output, session) {

anum <- reactiveValues(a = 0)
a    <- reactiveValues(acme = acme, f = NULL)
b    <- reactiveVal(acme)
cc   <- reactive(a$acme)


observeEvent(input$go, {
z      <-  sample(x = 1:100 , size = 1)
a$cach <- a$acme$clone()
anum$a <- anum$a + 1
a$acme$AddChild(paste0("New", z))
a$f    <- 0 #to force reaction
a$f    <-  a$acme
a$acme <- 0 #to force reaction
a$acme <- a$f
b(a$acme)
print("a$acme")
print(a$acme)
print("b()")
print(b())


})

### not working
output$text = renderPrint({
req(a$f)
print(a$f)})

output$text2 = renderPrint(print(cc()))

## now it works
observe({
print(identical(a$acme, a$cach)) #this is triggering the update
output$text1 = renderPrint(print(b()))

})
### working
observe({
anum$a
output$text3 = renderPrint(print(a$acme))
})
### working
observeEvent(eventExpr =  anum$a, handlerExpr = {
output$text4 = renderPrint(print(a$acme))

})


}
shinyApp(ui, server)

我认为a$acme$AddChild(paste0("New", z))方法在调用时没有被检测为更改。

相关内容

  • 没有找到相关文章

最新更新