Hi,
Im trying to build an event chain for a more complex app, but the problem can be seen in this small example. The idea is that the output of a text field should be given by either:
- a textInput, which can be transmitted to the text field by an action button "align"
- An action button "set_to_20", which will set first the text input and then the text field to 20
However, no matter what I do, the option 2 does not get transmitted immediately, only after pressing the button "set_to_20" a second time.
Why is this lagged? How to fix it?
Thanks a lot!
library(shiny)
ui <- fluidPage(
fluidRow(
column(width= 4,
textInput(inputId = "input1", label = "Select number of rows", value = "10"),
actionButton("go","set_to_20"),
actionButton("align","align_text")
),
column(width = 12,
verbatimTextOutput(outputId = "Id1"),
verbatimTextOutput(outputId = "Id2")
)
)
)
server <- function(input, output,session) {
start <- reactiveValues(new=0)
observeEvent("",{
start$new <- start$new+1
})
observeEvent(input$go,{
updateTextInput(session,"input1",value="20")
})
vals2 <- eventReactive({
input$go
input$align
start$new
},{
paste0(input$input1)
})
output$Id1 <- renderText({
vals2()
})
}
shinyApp(ui,server)