首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Power自定义R视觉(PBIVIZ)

Power自定义R视觉(PBIVIZ)
EN

Stack Overflow用户
提问于 2019-09-09 15:46:08
回答 1查看 898关注 0票数 2

**编辑;为了简单起见,我将举一个例子来说明我想做的事情。我需要加密我的密谋。下面是硬编码。

代码语言:javascript
复制
  p <- ggplot(data = Thisismydata, aes(x = thisismyX, fill = thisismyFill)) +
    geom_bar(position = "dodge")
  w = ggplotly(p)
  w =as_widget(w)
}

我需要一些动态的东西,所以我不必使用硬编码的columns.All,我必须将它与伪Python版本进行比较,如下所示;

代码语言:javascript
复制
  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创造一个视觉效果,我被困住了。刚开始的时候。这很奇怪。我用文字记录和Python制作了视觉效果,但我认为我从来没有在这么早的时候就被困在什么东西上。在Power中,我似乎找不到任何关于R自定义可视化的好的和最新的资源,所以我只能使用旧的YouTube视频和3岁的Github存储库。如果有人能帮我提供一些最新的信息,我将不胜感激。我的问题如下:

我已经开始建立一个基于三年前的YouTube视频的R视频。这可能是我的第一个错误。这也是一个PBIVIZ,而不是Power中的脚本窗口。在我的script.r文件中,我有一个

代码语言:javascript
复制
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');
####################################################```

这似乎什么也做不了。上面说我的价值观对象不存在..。但我是逐字按照他们的教程。我不知道这是如何工作的,但是在Power内部构建的脚本编辑器中,您可以使用索引来声明每个字段。我不记得正确的语法,所以我将使用Python作为示例。在Python中,如果您需要对视觉上的第一个字段执行一些操作,那么它将是dataset.iloc,0。我-假设-这就是这里发生的事,因为他们并没有真正解释。看起来像是某种索引..。目前,我的能力与我之前所做的构建相比都很古怪,但这并不是什么大不了的事情。我可以恢复到默认状态,并在以后进行处理。现在我只想搞点事情来策划。

我的终局不过是一张线表。

有人能告诉我我做错了什么吗?这些字段也需要是动态的,因为它们可以根据用户想要在其中添加的内容进行更改,所以我试图避免使用名称对其中的字段进行硬编码。

错误日志

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2019-09-09 15:52:24

欢迎来到社区!

R在Power BI中有点烦人。

  1. 因为它可能不知道你的get_wd()在哪里,所以它不会在里面源文件。试着把你的整个路径,甚至更好的,上传到一个在线的地方,看看这是否可行,或将数据导入PowerBI并从那里读取。
  2. 您必须确保POWER正在使用的R安装同时安装了ggplot2和巧妙安装。确保它是相同版本的R,否则它将无法工作。

试试看这2,如果它没有,张贴它给你的错误,我们将采取从那里。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57857273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档