The first issue is that conceptually the logic test for if to show the download button relied on button press being > 0 which it will always continue to be, so would never go away.
Since you already track a v$clearAll as a condition, it made sense to rely on that as a rule instead BUT conditional panel works via javascript, and it thus is a non-trivial issue to get it to know the status of shiny reactivevalues, therefore I simply replaced the conditionalpanel with a 'purer' shiny approach, for which access reactive values is trivial.
It seems to me that a refactor could be considered also, seperating out the plot logic, to a reactive, this could then be simply rendered, but also it could be req(uired) to dynamically show the download button, which would very slightly simplify that aspect
Finally, I observed that pressing run without any title or xaxis values, was possible, so I wanted to show that it would be easy to protect against that with a few req() calls.
Here is working R code for you
library(shiny)
library(ggplot2)
library(openxlsx)
ui = fluidPage(
textInput("textT", label = "Title", value = ""),
textInput("textX", label = "X-Axis Label", value = ""),
actionButton("Btn", "Run", icon=icon("play-circle")),
plotOutput('plot1'),
textOutput("btnout"),
textOutput("vclearAll"),
uiOutput("mydownloadui")
)
server = function(input, output, session) {
v <- reactiveValues(clearAll = TRUE)
output$btnout <- renderPrint({
paste0("input$Btn : ",input$Btn)
})
output$vclearAll <- renderPrint({
paste0("v$clearAll : ",v$clearAll)
})
observeEvent(c(input$textT, input$textX), {
v$clearAll <- TRUE
}, priority = 10)
observeEvent(input$Btn, {
output$plot1 = renderPlot({
req(input$textT)
req(input$textX)
if (v$clearAll)
return()
else
ggplot(mtcars, aes(x= gear, y= carb)) + geom_line() +ggtitle(input$textT) + xlab(input$textX)
})
output$mydownloadui <- renderUI({
req(input$textT)
req(input$textX)
if(v$clearAll)
return(NULL)
downloadButton("dwload", "Download")
})
output$dwload <- downloadHandler(
filename = function() {
paste0("Checks-", gsub(" ", "_", gsub(":", ".", Sys.time())), ".xlsx")
},
content = function(file) {
if (v$clearAll)
return()
else
quick_xlsx(mtcars, file=file)
}
)
v$clearAll <- FALSE
}, priority = 10)
}
shinyApp(ui, server)