-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client error console and duplicate input/output binding errors #3931
Conversation
… display better messages
…can pass more informative error messages
…oss init and dynamic renders
App that shows catching of duplicate IDs across static and dynamic UI library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
checkboxInput("showDynamicPlot", "Show dynamic plot")
),
mainPanel(
plotOutput("distPlot"),
# Uncomment this line to trigger initialization duplicate error
# plotOutput("distPlot", width = "50%"),
uiOutput("dynamicPlot"),
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
output$dynamicPlot <- renderUI({
if (input$showDynamicPlot) {
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
}
})
}
shinyApp(ui = ui, server = server) |
…n it. Also add a close button and a collapse one
…uch any error going on during the shiny "runtime"
Hello @nstrayer, great addition - it certainly has the potential to reduce confusion occasionally. I'm curious, though: could there be a feature to switch this off, perhaps through a setting, for instances where it might be preferable to keep it concealed in a production environment? Best, |
…an another message
… don't expose implementation
…cause the initShiny call is no longer dangling.
Hi Michael, This is a good point. Right now this only should catch errors that would have otherwise broken your app. We're going to try bringing it in where it is always active and then run our large suite of tests on Shiny to see if we're going to start causing spurious error messages to appear. If it becomes a problem then the plan would be to make it only show up when devmode is turned on for Shiny. |
…inputs and outputs
…between inputs and outputs" This reverts commit 0cff500.
…ve, and validate. The validation is now done after _bindAll() is called to get a complete picture of collisions.
In 34cf27e, I switched where the logic for throwing on duplicate ID bindings was. Now we let Shiny run through all the input and output bindings. Then after both
|
…ormatting of the duplicate id message
srcts/src/shiny/bind.ts
Outdated
// Check if ID is falsy, or if already bound, or has the same ID as | ||
// another input binding and if it is, skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix comment
srcts/src/shiny/bind.ts
Outdated
* duplicate IDs but in the future could be expanded to check more conditions | ||
* @returns ShinyClientError if current ID bindings are invalid, otherwise null | ||
*/ | ||
function getValidity(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to checkValidity
.
srcts/src/shiny/bind.ts
Outdated
|
||
if (duplicateIds.size === 0) return { status: "ok" }; | ||
|
||
const duplicateIdMsg = [...duplicateIds.entries()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a more efficient copying technique.
Conflicts: inst/www/shared/shiny.js inst/www/shared/shiny.js.map inst/www/shared/shiny.min.js inst/www/shared/shiny.min.js.map
What?
This PR adds a client-side error console for surfacing errors to the user that previously would go unseen unless they had their browser's devtools open.
Also included is special detection of duplicate input and output bindings which would previously silently either break your app (in the case of outputs) or cause confusing behavior (only first bound input would work.)
There is support for multiple errors:
The following test app will trigger input and output binding errors. (Note you'll need to comment out the second output to get the input error to show up because output binding errors stop the entire Shiny runtime.
How?
Adds two webcomponents:
shiny-error-console-container
andshiny-error-console
. A functionshowErrorInClientConsole(e)
adds the errors to the page (as children of ashiny-error-console-container
for layout purposes) as they come in.