**编辑;为简单起见,我将举一个示例说明我要执行的操作。 我需要对绘图进行软编码。下面是硬编码的。
p <- ggplot(data = Thisismydata, aes(x = thisismyX, fill = thisismyFill)) +
geom_bar(position = "dodge")
w = ggplotly(p)
w =as_widget(w)
}
我需要一些动态的东西,所以我不必使用硬编码的列。我所要比较的只是伪Python版本,就像这样;
p <- ggplot(data = dataset, aes(x = dataset.iloc[:,1], fill = dataset.iloc[:,2])) +
geom_bar(position = "dodge")
w = ggplotly(p)
w =as_widget(w)
}
我需要将这些声明为字段在字段中的位置,而不是按名称。这些将被大量交换,并且我不会弹出错误消息,因为有人在其值/列中使用了未声明的名称。**
我正在为Power BI创建视觉效果,但遇到了麻烦。一开始。这很奇怪。我已经使用Typescript和Python制作了视觉效果,但我认为我从没有像现在这样被卡住过。我似乎在Power BI中找不到任何有关R自定义视觉效果的优质且最新的资源,因此我只能使用旧的YouTube视频和3年的Github存储库。如果有人可以提供一些最新信息来帮助我,我将非常感激。我的问题如下;
我已经开始基于三年前的YouTube视频构建R视觉效果。这可能是我的第一个错误。这也是PBIVIZ,不是Power BI中的脚本窗口。我的script.r文件里面有这个
source('./r_files/flatten_HTML.r')
############### Library Declarations ###############
libraryRequireInstall("ggplot2");
libraryRequireInstall("plotly")
####################################################
################### Actual code ####################
g = plot_ly(x = Values[,1], y = Values[,2], text = paste("z:", Values[,3]),mode = "markers", color = Values[,3], size = Values[,1])
####################################################
############# Create and save widget ###############
p = ggplotly(g);
internalSaveWidget(p, 'out.html');
####################################################```
这似乎没有任何作用。它说我的Values对象不存在...但是我根据他们的教程逐字关注它。我不确定这是如何工作的,但是在Power BI内置的脚本编辑器中,您可以使用索引来声明每个字段。我不记得正确的语法,因此我将以Python为例。在Python中,如果您需要对视觉上的第一个字段执行某些操作,则应为dataset.iloc [,0]。我-假设-这就是这里发生的事情,因为他们没有真正解释它。看起来像是某种索引... 到目前为止,我的功能一直很时髦,但这并不是什么大不了的事情。我可以将其恢复为默认值,然后再进行处理。现在,我只想绘制一些东西。
我的最终比赛只是折线图。
谁能告诉我我在做什么错?这些字段也必须是动态的,因为它们可能会根据用户想要在其中扔的内容而变化,因此,我试图避免按名称硬编码其中的字段。
错误日志
Feedback Type:
Frown (Error)
Timestamp:
2019-09-09T16:03:19.3159296Z
Local Time:
2019-09-09T11:03:19.3159296-05:00
Session ID:
#####
Release:
August 2019
Product Version:
2.72.5556.801 (19.08) (x64)
Error Message:
R script error.
Loading required package: XML
Loading required package: htmlwidgets
Loading required package: ggplot2
Loading required package: plotly
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Error in plot_ly(x = Values[, 1], y = Values[, 2], text = paste("z:", :
object 'Values' not found
Execution halted
Stack Trace:
Microsoft.PowerBI.ExploreServiceCommon.ScriptHandlerException: R script error.
Loading required package: XML
Loading required package: htmlwidgets
Loading required package: ggplot2
Loading required package: plotly
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Error in plot_ly(x = Values[, 1], y = Values[, 2], text = paste("z:", :
object 'Values' not found
Execution halted
---> Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException: R script error.
Loading required package: XML
Loading required package: htmlwidgets
Loading required package: ggplot2
Loading required package: plotly
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Error in plot_ly(x = Values[, 1], y = Values[, 2], text = paste("z:", :
object 'Values' not found
Execution halted
at Microsoft.PowerBI.Scripting.R.RScriptWrapper.RunScript(String originalScript, Int32 timeoutMs)
at Microsoft.PowerBI.Client.Windows.R.RScriptHandler.GenerateVisual(ScriptHandlerOptions options)
--- End of inner exception stack trace ---
at Microsoft.PowerBI.Client.Windows.R.RScriptHandler.GenerateVisual(ScriptHandlerOptions options)
at Microsoft.PowerBI.ExploreServiceCommon.ScriptVisualCommandFlow.RunInternal(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreServiceCommon.ScriptVisualCommandFlow.Run(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.TransformDataShapeResult(QueryCommand transformCommand, SemanticQueryDataShapeCommand command, Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ExecuteDataQuery(IQueryResultDataWriter queryResultDataWriter, EngineDataModel engineDataModel, DataQuery query, Int32 queryId, ServiceErrorStatusCode& serviceErrorStatusCode, CancellationToken cancelToken)
at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ProcessAndWriteSemanticQueryCommands(IQueryResultsWriter queryResultsWriter, IList`1 queries, HashSet`1 pendingQueriesToCancel, EngineDataModel engineDataModel)
Invocation Stack Trace:
at Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
at Microsoft.Mashup.Client.UI.Shared.StackTraceInfo..ctor(String exceptionStackTrace, String invocationStackTrace, String exceptionMessage)
at Microsoft.PowerBI.Client.Windows.ErrorHostService.GetErrorDetails(ShowErrorDialogArgs args)
at Microsoft.PowerBI.Client.Windows.ErrorHostService.<>c__DisplayClass2_0.<<ShowErrorDialog>b__0>d.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
at Microsoft.PowerBI.Client.Windows.ErrorHostService.<>c__DisplayClass2_0.<ShowErrorDialog>b__0()
at Microsoft.Mashup.Host.Document.SynchronizationContextExtensions.<>c__DisplayClass1_0`1.<SendAndMarshalExceptions>b__0()
at Microsoft.Mashup.Host.Document.SynchronizationContextExtensions.<>c__DisplayClass0_1.<SendAndMarshalExceptions>b__0(Object null)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at Microsoft.Mashup.Client.UI.Shared.WebDialogs.WebDialog.<>n__0(IWindowHandle owner)
at Microsoft.Mashup.Client.UI.Shared.WindowManager.ShowModal[T](T dialog, Func`1 showModalFunction)
at Microsoft.PowerBI.Client.Program.<>c__DisplayClass4_0.<Main>b__1()
at Microsoft.PowerBI.Client.Windows.IExceptionHandlerExtensions.<>c__DisplayClass3_0.<HandleExceptionsWithNestedTasks>b__0()
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
at Microsoft.PowerBI.Client.Program.Main(String[] args)
OS Version:
Microsoft Windows NT 10.0.17134.0 (x64 en-US)
CLR Version:
4.7 or later [Release Number = 461808]
Peak Virtual Memory:
38.3 GB
Private Memory:
445 MB
Peak Working Set:
673 MB
IE Version:
11.950.17134.0
User ID:#####
Workbook Package Info:
1* - en-US, Query Groups: 0, fastCombine: Disabled, runBackgroundAnalysis: True.
Telemetry Enabled:
True
AS Live Connection:
True
Performance Trace Logs:
C:\Users\MYNAME\Microsoft\Power BI Desktop Store App\PerformanceTraces.zip
Enabled Preview Features:
PBI_userFavoriteResourcePackagesEnabled
Disabled Preview Features:
PBI_shapeMapVisualEnabled
PBI_SpanishLinguisticsEnabled
PBI_NewWebTableInference
PBI_showIncrementalRefreshPolicy
PBI_qnaLiveConnect
Disabled DirectQuery Options:
TreatHanaAsRelationalSource
Cloud:
GlobalCloud
DPI Scale:
100%
Supported Services:
Power BI
Formulas:
section Section1;
答案 0 :(得分:0)
欢迎社区!
Power BI中的R有点烦人。
get_wd()
的位置,所以它不会作为该文件的源。尝试把整个路径放到网上,甚至更好,将其上传到某个地方,看看是否行得通,或者将数据导入PowerBI并从那里读取。尝试那些2,如果没有,请发布错误提示,我们将从那里解决。