How to split jsCode into an independent js file?

10 views
Skip to first unread message

王雪松

unread,
Aug 23, 2017, 6:16:43 PM8/23/17
to Shiny - Web Framework for R
My idea is: add a dynamic text in header of dashboard.  Text Here
body <- dashboardBody(
    useShinyjs(),
    # This will call message-handler.js
    tags$head(tags$script(src = "js/alert_message.js"),
              tags$link(rel = "stylesheet", type = "text/css", href = "css/tmod.css")),
    tags$script(HTML('$(document).ready(function() {
                     $("header").find("nav").append(\'<span class="myClass"> Text Here </span>\');
                     })
                     ')),
    tabItems(
        tabItem(tabName = "file_preview",
The green area is how I add "Text Here" in header.  Of course, it is not dynamic text.

 Now, I try to split the code chunk into an independent js file. I have alert_message.js. Try to be dynamic!
Shiny.addCustomMessageHandler("header_message",
function(headerMessage){
$("header").find("nav").append('<span  class="myClass"> Text Here</span>', headerMessage)
}
);


# in server.R, I try to call js function. But it does not show any thing. 

observe({
        input$run
        mess <- "I am worried about you"
        session$sendCustomMessage(type="header_message", mess)
    })

Are there any mistakes in my jsFile or R file?

Thank you!
Song




王雪松

unread,
Aug 24, 2017, 4:17:29 AM8/24/17
to Shiny - Web Framework for R
I tried to include tags$script(src="//code.jquery.com/jquery-1.11.3.min.js") into my code. It can not run any more without errors, strangely.



在 2017年8月24日星期四 UTC+2上午12:16:43,王雪松写道:
Reply all
Reply to author
Forward
0 new messages