简体   繁体   中英

Need Hello world example for Tableau chart inside R shiny via javascript API

I'm experimenting to use tableau javascript api inside R shiny. I used shinyjs package to simplify the calls in shiny. The js involved comes from tableau's tutorial page.

After I clicked the 'Call Tableau Viz' button, nothing happened and the browser console shows Uncaught [object Object] error

(index):7504 Uncaught [object Object]VizImpl$Create @ (index):7504$tableauSoftware_Viz @ (index):4829initializeViz @ (index):8644shinyjs.init @ (index):34(anonymous function) @ (index):33_sendMessagesToHandlers @ shinyapp.js:515(anonymous function) @ shinyapp.js:626_sendMessagesToHandlers @ shinyapp.js:515dispatchMessage @ shinyapp.js:501c.onmessage @ shinyapp.js:114

This should be a very straight forward ones, however I do not know how to fix it.

library(shiny)
library(shinyjs)

jsCode <- "shinyjs.init = function(){initializeViz();}"

shinyApp(
  ui = fluidPage(
    includeScript("https://public.tableau.com/javascripts/api/tableau-2.1.0.js"),
    includeScript("http://onlinehelp.tableau.com/samples/en-us/js_api/tutorial.js"),
    useShinyjs(),
    extendShinyjs(text = jsCode),
    actionButton('trigger','Call Tableau Viz'),
    tags$div(id = 'tableauViz')
  ),
  server = function(input, output) {
    observeEvent(input$trigger, {
      js$init()
    })
  }
)

You have a small misunderstanding of the shinyjs.init function. It gets called automatically. Calling js$init() will not work. If you place a alert("hello") call inside the shinyjs.init function, you'll see that it gets called when the app starts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM