[英]Tableau JavaScript API filter function in Shiny R
I'm doing a test to integrate Tableau JavaScript API into an single-page shiny App. 我正在测试将Tableau JavaScript API集成到一个单页的闪亮应用程序中。 I've successfully rendered the Tableau Viz, but filter functions won't work.
我已经成功渲染了Tableau Viz,但过滤器功能无法正常工作。
Here's my code: 这是我的代码:
library(shiny)
library(shinyjs)
shinyApp(
ui = fluidPage(
useShinyjs(),
tags$head(tags$script(src="https://public.tableau.com/javascripts/api/tableau-2.min.js")),
extendShinyjs(text='shinyjs.initializeViz = function(){
var placeholderDiv = document.getElementById("tableauViz");
var url = "http://public.tableau.com/views/WorldIndicators/GDPpercapita";
var options = {
hideTabs: true,
hideToolbar: true,
onFirstInteractive: function () {
workbook = viz.getWorkbook();
activeSheet = workbook.getActiveSheet();
}
};
viz = new tableau.Viz(placeholderDiv, url, options);
}
shinyjs.filterSingleValue= function(filtername, value){
activeSheet.applyFilterAsync(
filtername,
value,
tableau.FilterUpdateType.REPLACE);
} '),
titlePanel("Tableau JavaScript API in Shiny App"),
selectInput('region', 'Region: ',
c('The Americas', 'Europe', 'Middle East')),
tags$div(id = 'tableauViz')
),
server = function(input, output, session){
observeEvent(input$region, {
js$filterSingleValue('Region', input$region)
js$initializeViz()
})
}
)
Any ideas why? 有什么想法吗?
Finally find a way out... For some reason, when converting JavaScript functions to shinyjs.function, it can only recognize one parameter, ie in this case rewrite the filter function by removing the first parameter: 最终找到一条出路...出于某种原因,将JavaScript函数转换为Shinyjs.function时,它只能识别一个参数,即在这种情况下,通过删除第一个参数来重写filter函数:
shinyjs.filterSingleValue= function(value) {
activeSheet.applyFilterAsync(
'Region',
value,
tableau.FilterUpdateType.REPLACE);
}
This should fix the problems. 这应该解决问题。 Thanks for anyone who spent your precious time on this...
感谢所有在此上花费您宝贵时间的人...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.