Call the output generated in UI to server using custom message

Is there a way to generate the output generated in UI to be rendered in server. Basically , whatever is input in numeric input (id = "hcontent"), output$tab to have +1

So by default the value is 2, so output$tab to have 3

library(shiny)
library(shinyjs)

ui <- fluidPage(
  
  # HTML('<p id="res">Value</p>'),
  # textInput("x", label = "Text"),
  # tags$script("document.getElementById('res').innerHTMl=x")
  
  HTML(
  
"<h1>Change the HTML content</h1>
<h2 id=\"hcontent\">2</h2> 
<h3>Welcome</h3>
<input id='x' type=\"number\" oninput = 'searchURL()'></input>
<script>  

function searchURL() {
     document.getElementById(\"hcontent\").innerHTML=x.value
}
</script> 

"
       
       
       ),
tags$script("Shiny.addCustomMessageHandler('handler1', searchURL)"),
htmlOutput("tab")
)

server <- function(input, output, session) {
  
  output$tab <- renderUI({
    session$sendCustomMessage("handler1", input$hcontent+1)
  })
}

shinyApp(ui, server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.