Is there a way to show the actionbutton in shiny only when Selectinput changes? For example assume I have selected choice A from selectinput. At this point the actionbutton will be disabled, but as soon as I add choice B in addition to A(and vice versa when you delete choice B), the action button will show again to confirm these changes? I apologise in advance for not providing a reproducible example because I did not know how to approach it.
Asked
Active
Viewed 36 times
1 Answers
1
Perhaps you are looking for this
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("actionona", "actionbutton on demand", c("A", "B"), selected=1),
selectInput("actiondisableb", "Disable When D is selected", c("C", "D")),
fluidRow( uiOutput("action1"), uiOutput("action2"))
),
mainPanel(
uiOutput('myvalue1'),
uiOutput('myvalue2')
)
)
)
server <- function(input, output, session){
output$action1 <- renderUI({
if(input$actionona=="A"){
actionBttn(inputId="plotbtn",
label="Action One",
style = "simple",
color = "success",
size = "md",
block = FALSE,
no_outline = TRUE
)
}else{
return(NULL)
}
})
output$action2 <- renderUI({
req(input$actiondisableb)
if (is.null(input$actiondisableb)) {
return(NULL)
}
else {
actionBttn(inputId="plotmebtn",
label="Action Two",
style = "simple",
color = "primary",
size = "md",
block = FALSE,
no_outline = TRUE
)
}
})
observeEvent(input$plotbtn, {
req(input$plotbtn)
if (input$plotbtn==0) {
return(NULL)
}else {
output$myvalue1 <- renderUI({
if (input$actionona=="A") {
tagList(
p("Blah Blah Blah 1", style = "color:red")
)
}else {return(NULL)}
})
}
})
observeEvent(input$plotmebtn, {
req(input$actiondisableb,input$plotmebtn)
if (input$plotmebtn==0) {
return(NULL)
}else {
output$myvalue2 <- renderUI({
if (input$actiondisableb=="C") {
tagList(
p("Blah Blah Blah 2", style = "color:blue")
)
}else {return(NULL)}
})
}
})
}
shinyApp(ui = ui, server = server)

YBS
- 19,324
- 2
- 9
- 27
-
Thank you very much YBS. It was very helpful :) – Jack Aug 09 '20 at 06:49