我正在按照本教程为PowerBI创建自定义视觉:http://radacad.com/create-custom-visual-with-r-and-json-part3
假设我在Power BI的自定义外观中使用默认数据:mtcars
。我正在尝试创建2个字段,假设"Mileage Per Gallon"
和"Cylinder Size"
如下:
这是我的 Script.R
source('./r_files/flatten_HTML.r')
############### Library Declarations ###############
libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly")
####################################################
################### Actual code ####################
ValuesWithChangedName <- data.frame(mpgWithChangedName, cylWithChangedName)
p <- plot_ly(ValuesWithChangedName,
type = 'scatterpolar',
r = ValuesWithChangedName$mpgWithChangedName,
theta = ValuesWithChangedName$cylWithChangedName,
mode = 'markers'
)
####################################################
############# Create and save widget ###############
#p = ggplotly(p);
internalSaveWidget(p, 'out.html');
####################################################
和capabilities.json :
{
"dataRoles": [
{
"displayName": "Mileage Per Gallon",
"kind": "GroupingOrMeasure",
"name": "mpgWithChangedName"
},
{
"displayName": "Cylinder Volume",
"kind": "GroupingOrMeasure",
"name": "cylWithChangedName"
}
],
"dataViewMappings": [
{
"scriptResult": {
"dataInput": {
"table": {
"rows": {
"select": [
{
"for": {
"in": "mpgWithChangedName"
}
},
{
"for": {
"in": "cylWithChangedName"
}
}
],
"dataReductionAlgorithm": {
"top": {}
}
}
}
},
"script": {
"scriptProviderDefault": "R",
"scriptOutputType": "html",
"source": {
"objectName": "rcv_script",
"propertyName": "source"
},
"provider": {
"objectName": "rcv_script",
"propertyName": "provider"
}
}
}
}
],
"objects": {
"rcv_script": {
"properties": {
"provider": {
"type": {
"text": true
}
},
"source": {
"type": {
"scripting": {
"source": true
}
}
}
}
}
},
"suppressDefaultTitle": true
}
在这种简单情况下,我没有绘制图表,而是得到了空白图表。 有人可以指出我正在做的错误吗?