library(shiny)
library(shinyjs)
ui <- basicPage(
useShinyjs(),
fluidRow(
column(
width = 6,
textInput('a', 'Text A',"a1"),
textInput('b', 'Text B',"b1"),
# textInput('c', 'Text A',"c1"),
# textInput('d', 'Text B',"d1"),
# textInput('e', 'Text A',"e1"),
textInput('f', 'Text B',"f1"),
selectInput('gh', "select", choices = c(1,2,5,6,7), selected = 1),
actionButton("sub", "Submit"),
actionButton("ret", "auto click"),
uiOutput('f2'),
uiOutput('f3')
),
column(
width = 6,
tags$p(tags$span(id = "valueA", "")),
tags$script(
"$(document).on('shiny:inputchanged', function(event) {
if (event.name === 'a') {
$('#valueA').text(event.value);
}
});
"
)
,tableOutput('show_inputs')
)
)
)
server <- shinyServer(function(input, output, session){
# output$f2 <- renderUI({
# if(input$a == "a2"){
# textInput('ren', 'ren B',"ren z1")
# } else {
# NULL
# }
# })
AllInputs <- reactive({
x <- reactiveValuesToList(input)
})
asd <- reactiveValues()
observeEvent(input$sub,{
asd$df <- c(6,9)
output$f2 <- renderUI({
selectInput('f2', "select", choices = c(6,9), selected = asd$df)
})
output$f3 <- renderUI({
actionButton("new", "Generate iris table")
})
})
observeEvent(input$new, {
output$show_inputs <- renderTable({
head(iris)
})
})
observeEvent(input$ret,{
asd$df <- 9
sad <- data.frame(a = c("gh"), b = c(7))
updateSelectInput(session, inputId = sad$a, selected = sad$b)
click('sub')
updateSelectInput(session, inputId = "f2", selected = asd$df)
click('new') ### to generate IRIS table
# click('new')
})
})
shinyApp(ui = ui, server = server)
The process, when you click on "auto click", there is a button "Generate iris table" popping up and also this button should be get auto clicked so that iris table gets populated.
But here only "Generate iris table" button is popping up and no iris table getting displayed. But if you click again on "auto click" button , we can see iris button
Expected output The moment user clicks on "auto click", both "Generate iris table" button and iris table should be displayed