闪亮的 renderText 对 reactiveValues 的变化没有反应
Shiny renderText not reacting to change in reactiveValues
我的应用程序中有一个令人沮丧的小问题。此对象 output$timeheader <- renderText() 在 user$stationtype 或 user$stationvar 更改时不响应,但仅在 stationname() 更改时响应。
我已经尝试制作一个 reprex,但我无法重现该错误。它按本例中的预期工作。在我的应用程序中,对 user$stationtype 或 user$stationvar 的更改不会触发 output$timeheader <- renderText().
library(shiny)
ui <- tagList(
navbarPage(
title = "navbarPage",
tabPanel(
title = "tabPanel",
tags$div(
absolutePanel(
tabsetPanel(
tabPanel(
title = "title",
tags$div(
actionButton("changesel", "Choose a different variable"),
textInput("map_marker_click", "Enter station name"),
h4(strong(textOutput("timeheader")))
)
)
)
)
)
)
)
)
server <- function(input, output, session){
# collect inputs needed by model
user <- reactiveValues(
stationvar = NA,
stationtype = NA
)
# observe changes in ui and pass to user$
observe({
input$changesel # observe button click
ot <- runif(1)
isolate({
obsnut <- ifelse(ot > 0.6, "DIN", "NONE") # obs to use
obsgroup <- ifelse(ot > 0.3, "Streams", "none")
if (!setequal(obsnut, user$stationvar)){
cat("user$stationvar <-", obsnut, "\n")
user$stationvar <- obsnut
}
if (!setequal(obsgroup, user$stationtype)){
cat("user$stationtype <-", obsgroup, "\n")
user$stationtype <- obsgroup
}
}) # end isolate
})
# timeheader ####
output$timeheader <- renderText({
# req(user$stationtype, user$stationvar)
# FIXME why doesn't this stupid text show!!! ####
cat("Time series header:", user$stationtype, stationname(), user$stationvar, "\n")
if (isTRUE(stationname() > "")){
"Time series plot:"
} else if (isTRUE(user$stationvar != "NONE")){
"Enter station name to view data:"
} else {
""
}
})
## click on marker to get stationname ####
stationname <- reactive({
req(isTRUE(user$stationvar != "NONE"))
cat("Marker click\n")
input$map_marker_click
})
}
shinyApp(ui, server)
我的猜测是它与 stationame
反应因 req
为空有关。尝试:
stationname <- eventReactive(input$map_marker_click,{
req(isTRUE(user$stationvar != "NONE"))
cat("Marker click\n")
input$map_marker_click
}, ignoreNULL = F)
我的应用程序中有一个令人沮丧的小问题。此对象 output$timeheader <- renderText() 在 user$stationtype 或 user$stationvar 更改时不响应,但仅在 stationname() 更改时响应。
我已经尝试制作一个 reprex,但我无法重现该错误。它按本例中的预期工作。在我的应用程序中,对 user$stationtype 或 user$stationvar 的更改不会触发 output$timeheader <- renderText().
library(shiny)
ui <- tagList(
navbarPage(
title = "navbarPage",
tabPanel(
title = "tabPanel",
tags$div(
absolutePanel(
tabsetPanel(
tabPanel(
title = "title",
tags$div(
actionButton("changesel", "Choose a different variable"),
textInput("map_marker_click", "Enter station name"),
h4(strong(textOutput("timeheader")))
)
)
)
)
)
)
)
)
server <- function(input, output, session){
# collect inputs needed by model
user <- reactiveValues(
stationvar = NA,
stationtype = NA
)
# observe changes in ui and pass to user$
observe({
input$changesel # observe button click
ot <- runif(1)
isolate({
obsnut <- ifelse(ot > 0.6, "DIN", "NONE") # obs to use
obsgroup <- ifelse(ot > 0.3, "Streams", "none")
if (!setequal(obsnut, user$stationvar)){
cat("user$stationvar <-", obsnut, "\n")
user$stationvar <- obsnut
}
if (!setequal(obsgroup, user$stationtype)){
cat("user$stationtype <-", obsgroup, "\n")
user$stationtype <- obsgroup
}
}) # end isolate
})
# timeheader ####
output$timeheader <- renderText({
# req(user$stationtype, user$stationvar)
# FIXME why doesn't this stupid text show!!! ####
cat("Time series header:", user$stationtype, stationname(), user$stationvar, "\n")
if (isTRUE(stationname() > "")){
"Time series plot:"
} else if (isTRUE(user$stationvar != "NONE")){
"Enter station name to view data:"
} else {
""
}
})
## click on marker to get stationname ####
stationname <- reactive({
req(isTRUE(user$stationvar != "NONE"))
cat("Marker click\n")
input$map_marker_click
})
}
shinyApp(ui, server)
我的猜测是它与 stationame
反应因 req
为空有关。尝试:
stationname <- eventReactive(input$map_marker_click,{
req(isTRUE(user$stationvar != "NONE"))
cat("Marker click\n")
input$map_marker_click
}, ignoreNULL = F)