Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mcclurej
Helper I
Helper I

Power BI and R Shiny

So way back in 2016 there were some help messages on here around R Shiny becoming compatible in the future with Power BI.
Since that time, shiny has now become listed as compatible with Power BI.

Now, I would assume this meant that you could just render a Shiny app in a visualisation, but this doesnt work (comes up with error that no visualisation was output). So, okay, fair enough, I will learn me some visualisation devleopment.

I go through the process of learning how to build, package, and compile visualisations, and even test the visual with a rpivotTable visual so as to see that I did the thing correctly. I did, it was magnificant (one pivot table in all its glory 😛 ). At this point I was stoked, and wrote out a thousand line codebase for some shiny shiny app work (read: copied it from an exsisting code base and modified to fit the visualisation requirements). 

After working out the loading bugs (invalid libraries, bad syntax, ugly symantics), I was able to get the package to compile and load into Power BI, only to be presented with the following error:

 

 

Feedback Type:
Frown (Error)

Timestamp:
2021-11-22T22:54:02.1443239Z

Local Time:
2021-11-23T09:54:02.1443239+11:00

Session ID:
061232e8-0747-4f32-9bd8-52d43b2c9c17

Release:
October 2021

Product Version:
2.98.683.0 (21.10) (x64)

Error Message:
R script error.
Loading required package: xml2
Loading required package: htmlwidgets
Loading required package: dbplyr
Loading required package: DBI
Loading required package: tidyverse
-- Attaching packages ------------------------------------------------------------------------------- tidyverse 1.3.1 --
v ggplot2 3.3.5     v purrr   0.3.4
v tibble  3.1.5     v dplyr   1.0.7
v tidyr   1.1.4     v stringr 1.4.0
v readr   2.0.1     v forcats 0.5.1
-- Conflicts ---------------------------------------------------------------------------------- tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::ident()  masks dbplyr::ident()
x dplyr::lag()    masks stats::lag()
x dplyr::sql()    masks dbplyr::sql()
Loading required package: rpivotTable
Loading required package: DT
Loading required package: XML
Loading required package: shiny

Attaching package: 'shiny'

The following objects are masked from 'package:DT':

    dataTableOutput, renderDataTable

Loading required package: shinycssloaders
Error in .getNamespace(pkg) : 
  invalid type/length (symbol/0) in vector allocation
Calls: internalSaveWidget ... file.exists -> system.file -> devtools_loaded -> .getNamespace
Execution halted


Stack Trace:
Microsoft.PowerBI.ExploreServiceCommon.ScriptHandlerException: R script error.
Loading required package: xml2
Loading required package: htmlwidgets
Loading required package: dbplyr
Loading required package: DBI
Loading required package: tidyverse
-- Attaching packages ------------------------------------------------------------------------------- tidyverse 1.3.1 --
v ggplot2 3.3.5     v purrr   0.3.4
v tibble  3.1.5     v dplyr   1.0.7
v tidyr   1.1.4     v stringr 1.4.0
v readr   2.0.1     v forcats 0.5.1
-- Conflicts ---------------------------------------------------------------------------------- tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::ident()  masks dbplyr::ident()
x dplyr::lag()    masks stats::lag()
x dplyr::sql()    masks dbplyr::sql()
Loading required package: rpivotTable
Loading required package: DT
Loading required package: XML
Loading required package: shiny

Attaching package: 'shiny'

The following objects are masked from 'package:DT':

    dataTableOutput, renderDataTable

Loading required package: shinycssloaders
Error in .getNamespace(pkg) : 
  invalid type/length (symbol/0) in vector allocation
Calls: internalSaveWidget ... file.exists -> system.file -> devtools_loaded -> .getNamespace
Execution halted
 ---> Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException: R script error.
Loading required package: xml2
Loading required package: htmlwidgets
Loading required package: dbplyr
Loading required package: DBI
Loading required package: tidyverse
-- Attaching packages ------------------------------------------------------------------------------- tidyverse 1.3.1 --
v ggplot2 3.3.5     v purrr   0.3.4
v tibble  3.1.5     v dplyr   1.0.7
v tidyr   1.1.4     v stringr 1.4.0
v readr   2.0.1     v forcats 0.5.1
-- Conflicts ---------------------------------------------------------------------------------- tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::ident()  masks dbplyr::ident()
x dplyr::lag()    masks stats::lag()
x dplyr::sql()    masks dbplyr::sql()
Loading required package: rpivotTable
Loading required package: DT
Loading required package: XML
Loading required package: shiny

Attaching package: 'shiny'

The following objects are masked from 'package:DT':

    dataTableOutput, renderDataTable

Loading required package: shinycssloaders
Error in .getNamespace(pkg) : 
  invalid type/length (symbol/0) in vector allocation
Calls: internalSaveWidget ... file.exists -> system.file -> devtools_loaded -> .getNamespace
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.ExploreHost.SemanticQuery.ScriptVisualCommandFlow.RunInternal(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
   at Microsoft.PowerBI.ExploreHost.SemanticQuery.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__DisplayClass4_0.<ShowErrorDialogCore>b__0()
   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.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
   at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
   at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
   at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
   at System.Windows.Forms.WindowsFormsSynchronizationContext.Send(SendOrPostCallback d, Object state)
   at Microsoft.PowerBI.Client.Windows.Services.UIBlockingService.AllowModalDialogs(Action action)
   at Microsoft.PowerBI.Client.Windows.HostServiceDispatcher.<>c__DisplayClass5_0.<ExecuteOnUIThread>b__0(Object t)
   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.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.19043.0 (x64 en-US)

CLR Version:
4.7 or later [Release Number = 528372]

Peak Virtual Memory:
103 GB

Private Memory:
804 MB

Peak Working Set:
1.05 GB

IE Version:
11.789.19041.0

User ID:
277be003-afa8-4605-9336-04220d64b331

Workbook Package Info:
1* - en-AU, Query Groups: 0, fastCombine: Disabled, runBackgroundAnalysis: True.

Telemetry Enabled:
True

Snapshot Trace Logs:
C:\Users\jmcclure\AppData\Local\Microsoft\Power BI Desktop\FrownSnapShotd8612c1d-1fe9-4122-b444-fd233c87d808.zip

Model Default Mode:
Import

Model Version:
PowerBI_V3

Performance Trace Logs:
C:\Users\jmcclure\AppData\Local\Microsoft\Power BI Desktop\PerformanceTraces.zip

Enabled Preview Features:
PBI_compositeModelsOverAS
PBI_dynamicParameters
PBI_rdlNativeVisual

Disabled Preview Features:
PBI_shapeMapVisualEnabled
PBI_SpanishLinguisticsEnabled
PBI_qnaLiveConnect
PBI_azureMapVisual
PBI_dataPointLassoSelect
PBI_enhancedTooltips
PBI_enableWebView2

Disabled DirectQuery Options:
TreatHanaAsRelationalSource

Cloud:
GlobalCloud

DPI Scale:
100%

Supported Services:
Power BI

Formulas:


section Section1;

shared bn_quotas = let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lZRda4MwGEb/SvB2hTV+MHbZQcYGoxQmg1F6ka2BChIhjRv++9n1Qslrnry9U3qO2sOj+3321DvbmGyV5YMTO+1Pv3oYz16tN85q33RWt+P5OjusovCm9UJZ7y7HBQKVdV3bmqPY9u58+blC9M6ZH1Eb5xv9f+kcwfXmWd1/qFrYTqhtiv402gmZj0cyeOBi5O5EeUuMJWWepErjqTBLTpiHoZBIDGdKlV/pN93bb3P2nWWuBgg0E4AjkYCxnAgIkUDAmOVZ+LecNZVMb96Key+STDJF8u4xPfoaLhTEM3u43uql+9LOJycmK0TTfUXAyLYidFingI9MmkiITyXKgON/m6ACotyyISiFhThOshPr8/Q+HK0Z0rtZI3qeSMLr0joQD7s8QpoUwXi8BX85UJlnYeCkDcMJAzEUUonhTKlG+PAH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [campus = _t, pathway = _t, cohort = _t, quota = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"campus", type text}, {"pathway", type text}, {"cohort", type text}, {"quota", Int64.Type}})
in
    #"Changed Type";

shared paramed_quotas = let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCq5MyUutVNJRCnAMcvR1dQGyQhzdXPXDXEMU8vIVXP2AAoYGSrE6WJVGpiYWKRgaAVmmONUEFKWWKYSkFpVkJhaBZEwgKj3ykxKLSvBbbIJLJcJeI5ymodsLUhkLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [campus = _t, pathway = _t, cohort = _t, quota = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"campus", type text}, {"pathway", type text}, {"cohort", type text}, {"quota", Int64.Type}})
in
    #"Changed Type";

shared quotas = let
    Source = Table.Combine({bn_quotas, paramed_quotas})
in
    Source;

 

 



Of specific note is:
Error in .getNamespace(pkg): invalid type/length (symbol/0) in vector allocation
Calls: internalSaveWidget ... file.exists -> system.file -> devtools_loaded -> .getNamespace
Execution halted


HoNeStLy....I have no idea what this means.


I am assuming because shiny runs in a live app that something strange is going on?

In any case, here is the output script in script.r of my visual in case this sheds some light on my ignorance:

 

 

### blah blah blah, lots of code and then this:
###### shiny app call #############

p = shinyApp(ui = ui, server = server)

##p$sizingPolicy$browser$padding <- 0 ## tried this...didn't work...leaving here for the inevitible, "did you try this."
####################################################

############# Create and save widget ###############
###p = rpivotTable(quotaModelHi,rows=c("pathway","cohort"), cols=c("campus"),vals="offer",aggregatorName="Sum");
internalSaveWidget(p, 'out.html');
####################################################

################ Reduce paddings ###################
ReadFullFileReplaceString('out.html', 'out.html', ',"padding":[0-9]*,', ',"padding":0,')
####################################################

 

 

 

Any help or insight anyone can provide would be greatly appreciated.

2 REPLIES 2
mcclurej
Helper I
Helper I

Hello @v-yiruan-msft 
Thank you for your advice, unfortunately, I have already seen these via google search. 
If you look at my last code block in my post you would see:

##p$sizingPolicy$browser$padding <- 0 ## tried this...didn't work...leaving here for the inevitible, "did you try this."

So yeah.

In any case, the comparison article is just that, a comparison. It doesn't answer my question of how to utilise Shiny in Power BI when it is listed as being compatible.

I would assume that the Power BI widget in Power BI would render the Shiny App as though it were a web page. However, I don't believe this is even possible as there is a timeout function on any R Script enginge calls (think it's 15 seconds). Since Shiny Opens the console and keeps it open until the app is closed...this doesn't seem compatible...however, Shiny is listed as compatible with Power BI...meaning that this should be possible...no?

The documentation on compatible apps couldn't be wrong could it?

v-yiruan-msft
Community Support
Community Support

Hi @mcclurej ,

There is a post here with a similar problem to yours, please check the answers in it to test if it can also solve your problem.

Change sizing policy of a widget in R and save it
Also, the following are examples of shiny usage, you can check them out and hopefully they give you some insight and clue.

PowerBI vs. R Shiny: Two Popular Excel Alternatives Compared

Dashboarding with R Shiny

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.