-
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
Form input tags cannot have id="nodeName"
or id="nodeType"
inside sidebarPanel()
#4192
Comments
In a relatively recent version of Shiny, we started disabling the download button until the download handler is registered on the server side. This protects you against a bunch of weirdness that can happen with the download button if you don't have a handler in place. What's very likely is that there's an ID conflict in your app. Check your input/output IDs, or run your app with Here's a working version of your app: library(shiny)
ui <- fluidPage(
selectInput("x", "X", choices = c("A", "B")),
downloadButton(outputId = "y", label = "Y"),
)
server <- function(input, output, session) {
output$y <- downloadHandler(
filename = function() {
"sample_data.csv"
},
content = function(file) {
# Create some sample data
data <- data.frame(
ID = 1:5,
Name = c("Alice", "Bob", "Charlie", "David", "Eve"),
Value = rnorm(5)
)
# Write the data to a CSV file
write.csv(data, file, row.names = FALSE)
}
)
}
shinyApp(ui, server) |
Thank you for the assist - I was able to get to the bottom of this, kind of. I did indeed leave out important context in my original post - I named the Here is a minimal breaking example building on the last one: library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("nodeType", "X", choices = c("A", "B")),
downloadButton(outputId = "y", label = "Y")
),
mainPanel("empty")
)
)
server <- function(input, output, session) {
output$y <- downloadHandler(
filename = function() {
"sample_data.csv"
},
content = function(file) {
# Create some sample data
data <- data.frame(
ID = 1:5,
Name = c("Alice", "Bob", "Charlie", "David", "Eve"),
Value = rnorm(5)
)
# Write the data to a CSV file
write.csv(data, file, row.names = FALSE)
}
)
}
shinyApp(ui, server) |
Actually, I wonder if this is related to downloadButton being in sidebarPanel, which should contain input controls only? |
It's much much more likely that there's a conflict in your IDs. Can you go back to the state when the app wasn't working? If so, with the app open in the browser, if you open the browser's developer tools (by right-clicking anywhere on the page and selecting "Inspect" or "Inspect element"), the Console tab should have warnings or error messages pointing to duplicate ID problems. |
Thanks - there are no warnings about duplicates (I tried refresh also). The above was a pretty compact breaking example. If you remove the sidebarLayout/sidebarPanel/mainPanel the button won't be disabled and if you replace "nodeType" with something else it also won't be disabled. So I think internally |
Wow. Sorry, I hadn't run the example yet, but you're right! That's... bizarre. Here's the smallest reprex I can make, which comes down to having a library(shiny)
ui <- fluidPage(
tags$form(
tags$select(id="nodeType"),
downloadButton(outputId = "y", label = "Y"),
)
)
server <- function(input, output, session) {
output$y <- downloadHandler(
filename = function() "sample.txt",
content = function(file) {
writeLines(Sys.time(), file)
}
)
}
shinyApp(ui, server) The ui <- bslib::page_sidebar(
sidebar = sidebar(
tags$select(id="nodeType"),
downloadButton(outputId = "y", label = "Y"),
)
) I'm amazed that the reprex doesn't throw any console errors, but I can get a console error by changing ...actually even this causes an console error: ui <- fluidPage(
tags$form(
tags$select(id="nodeName")
)
)
I'm going to re-open the issue because this is clearly not expected! |
Seems like this is also an old and still open issue in React: https://github.com/search?q=repo%3Afacebook%2Freact+%22nodeName.toLowerCase%22&ref=opensearch&type=issues |
Also any form input elements with the
|
id="nodeName"
or id="nodeType"
inside sidebarPanel()
Yuck (see method 3 in the question) |
WOW, this is the safe way to read
and even then it's breaking encapsulation pretty hard! |
I am on Shiny 1.10.0
If I create a downloadButton in an app it appears enabled. If I create a selectInput before the downloadButton it becomes disabled at startup.
See reprex.
System details
Browser Version:
Output of
sessionInfo()
:Steps to reproduce the problem
Created on 2025-02-25 with reprex v2.1.0
The text was updated successfully, but these errors were encountered: