jcubic
jcubic

Reputation: 66650

renderText don't work in shiny

I have reactive output:

{{ textOutput("fatalError") }}

it generate tag:

<div id="fatalError" class="shiny-text-output shiny-bound-output"></div>

I have code like this:

.events$fatalError <- list(
   errorMessage = "Unknow Error",
   index = 0L
)
makeReactiveBinding("fatalError", env = .events)

and I'm triggering the event like this:

fatalError <- function(errorMessage) {
  # the error is shown, the class fatal-error indicate that tag should be visible
  addClass(selector = "body", class = "fatal-error")
  .events$fatalError <- list(
    errorMessage = errorMessage,
    index = .events$fatalError$index + 1L
  )
}

but the fatalError output is not updated, I've tried this (in server.R):

observeEvent(.events$fatalError, {
    # the message is printed to console
    print(.events$fatalError$errorMessage)
    output$fatalError <- renderText(.events$fatalError$errorMessage)
}, ignoreInit = TRUE)

and also this:

output$fatalError <- renderText({
    .events$fatalError$errorMessage
})

but the tag remain empty, I've also try to trigger the event when output$fatalError is visible on page and have the same results

Upvotes: 0

Views: 702

Answers (1)

jcubic
jcubic

Reputation: 66650

Found the issue, the output element can't be hidden when rendering otherwise it will not work (it's probably optimization "feature"), and maybe because addClass don't wait for the class to be addded before next line is executed so the renderText got not visible output.

Upvotes: 1

Related Questions