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
shiny app will not work if the same "output" is used two times in Ui.R #743
Comments
Yes, Shiny doesn't support multiple outputs with the same name. This code would generate HTML where two elements have the same ID, which is invalid HTML. I agree that it would be nice to have a warning/error for this. Unfortunately isn't a simple way to do this. The validation process would require Shiny looking at the entire HTML document and checking for multiple instances of each ID. Presently there's nothing like this in Shiny, although it might not be a bad idea to add a validation stage that checks for this and other things. |
I think there's an error message in the JavaScript console of the browser at least. Although admittedly those are easy to miss. |
Sorry to come up with this again, but is there an easy way to display things twice? Let's assume I'd like to show the same |
You don't need the same id to show the same thing. The easiest way would be to encapsulate all your logic and input dependencies in a library(shiny)
library(datasets)
# Define UI
ui <- fluidPage(
selectInput('data', 'Choose dataset', c('cars', 'faithful')),
numericInput('obs', 'How many obs to include?', 5),
plotOutput('p1'),
plotOutput('p2')
)
# Server logic
server <- function(input, output, session) {
currentData <- reactive({
data <- switch(input$data,
"cars" = cars, "faithful" = faithful)
head(data, n = input$obs)
})
output$p1 <- renderPlot({
plot(currentData())
})
output$p2 <- renderPlot({
plot(currentData())
})
}
# Complete app with UI and server components
shinyApp(ui, server) |
Or you can try modularising your app , using shiny modules. There's a link here to help https://www.ardata.fr/en/post/2019/02/11/why-using-modules/ |
The example provided by @bborgesr can be reduced a little more by using:
|
I'm having an issue where if I run my Shiny app 'maximized' on the same monitor where the IDE runs (R Workbench), it takes about 20 seconds to render. Otherwise if the app is minimized, or runs maximized on another display other than where the IDE runs, the app renders quickly without lag. Maybe this is the wrong place to address my issue but I am hoping to find an answer as it's an odd behavior I cannot find an answer to. Thank you. |
This was a great solution. Was looking to add a consistent title (uiOutput) across multiple tabs. |
If the same "output" slot is referenced two times in Ui.R, the browser will not output results nor will the shiny app issue any errors for debugging.
I do not know if this is more of a browser issue than that of shiny, but I think some kind of warning/error message would be appropriate in this case.
Below is example code for reproducing the issue.
Server.R:
Ui.R
The text was updated successfully, but these errors were encountered: