I am trying to replicating the HTML code to shiny. But it does not work. But pure HTML without shiny works. Basically Whatever I put in the box, the typeof should return.
You can refer my previous post here Get type of value entered
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(collapsed = TRUE),
dashboardBody(
HTML('<p id="res">Value</p><input type="text" id="fname" name="fname"><br><br>'),
tags$script(
"document.getElementById('fname').addEventListener('input', e => {
const value = e.currentTarget.value;
const checkType = isNaN(Number(value)) ? value : Number(value)
document.getElementById('res').textContent = typeof checkType
})"),
useShinyjs(),
actionButton("release", "Release"))
)
server <- function(input, output) {
observeEvent(input$release,{
# tags$head(tags$script("$('body').toggleClass('sidebar-collapse');"))
toggleClass(selector = 'body', class = 'sidebar-collapse')
# js$toggleCollapse()
})
}
shinyApp(ui, server)