1

**编辑; 为简单起见,我将举例说明我正在尝试做的事情。我需要对我的绘图进行软编码。下面是硬编码的。

  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;
4

1 回答 1

0

欢迎来到社区!

Power BI 中的 R 有点烦人。

  1. 它不会获取该文件,因为它可能不知道您的get_wd(). 尝试把你的整个路径,或者更好的是,将它上传到网上的某个地方,看看是否可行,或者将数据导入 PowerBI 并从那里读取。
  2. 您必须确保 POWER BI 正在使用的 R 安装同时安装了 ggplot2 和 plotly 。确保它与 R 的版本完全相同,否则它将无法工作。

试试这两个,如果没有,发布它给你的错误,我们会从那里拿走它。

于 2019-09-09T15:52:24.463 回答