Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Difference between writing JS/HTML code in .HTML file and shiny

When I write the below code in .html and execute, it works fine

<h1>Change the HTML content</h1>
<h2 id="hcontent">Hello Manu</h2> 
<h3>Welcome</h3>
<button type="button" onclick="document.getElementById('hcontent').innerHTML='Hello Mr. Manu'">Click here</button>

But, when I write the same in shiny, it does not. Can anyone help me on how to execute it?

library(shiny)
library(shinyjs)
# source("myfun.R")

ui <- fluidPage(
  useShinyjs(),
tags$head(HTML("<h1> Chnge the html content </h1>
<h2 id = 'hcontent'> Hello Vinay </h2> 
<h3> Welcome </h3>
<button type = 'button' onclick='document.getElementById('hcontent').innerHTML='Hello Mr Vinay'>Click here </button>"))
)

server <- function(input, output, session) {

  
}

shinyApp(ui, server)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem were the quotes. Try the following

HTML("<h1>Change the HTML content</h1>
<h2 id=\"hcontent\">Hello Vinay</h2> 
<h3>Welcome</h3>
<button type=\"button\" onclick='document.getElementById(\"hcontent\").innerHTML=\"Hello Mr. Vinay\"'>Click here</button>")
)

Don't use tags$head() because that will place the code in the <head> tag

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!