R-studio 9.0 Registration Key

0 views
Skip to first unread message

Basa Benejan

unread,
Aug 3, 2024, 6:07:41 PM8/3/24
to magbackcospcons

I'm looking for a user registration/log in code template for r/shiny. It need not be secure, just a way to personalize the content on a shiny app based on previous user settings. I don't want to rely too much on server services (such as accessing cookies)

So far I've been trying to do it myself, using a set of reactive variables (other than the input/output) on the client side, that remember the state of the session. The code became a bit ugly and I wonder if there is something simpler that I can reuse.

Facing the problem like yours I'm developing a package shiny.reglog. It allows anonymous users to look through your app, but also allows user to register. Server-side can access the user id of the logged user for inter-session recognition.

Disclaimer: This page discusses a Microsoft-developed open source package, which was at version 2.3.4 at the time of this writing. Readers should refer to the Microsoft365R package documentation developed by Hong Ooi for the most up-to-date information.

Microsoft 365 is a subscription extension of the Microsoft Office product line with cloud hosting support. The Microsoft-supported method for interfacing with R is the Microsoft365R package which was developed by Hong Ooi and has extensive documentation. It supports access to Teams, SharePoint Online, Outlook, and OneDrive.

This article describes approaches for authentication to Microsoft 365 using the Microsoft365R R package for use with the Posit professional products. Examples for interacting with data from SharePoint and writing data in pins format to SharePoint are included.

Under the hood, Microsoft365R is using the AzureAuth and AzureGraph packages, also developed by Hong Ooi, for authentication, token management, and access to the Graph API. In some cases, for example with troubleshooting or to remove interactive prompts in scheduled content, calling those packages directly to manage tokens is useful.

Enabling the device code workflow is through the App Registration dashboard in Azure -> click on the created app -> Authentication -> Allow public client flows and setting Enable the following mobile and desktop flows to yes. The device code workflow does not need Redirect URLs. Instead, this method provides a code and a link for the developer to access in a separate browser window (or even on a separate device) for sign-in.

A custom app will need to be registered in Azure with Application permissions. The permissions can be based off of the user permissions but can be assigned as needed for the application and to comply with any security restrictions.

Application permissions are more powerful than user permissions so it is important to emphasize that exposing the client secret directly should be avoided. As a control, using environment variables for storing the client secret is recommended. Connect allows Environment Variables. The variables are encrypted on-disk, and in-memory.

The credentials being embedded can be a user or a service account, as long as access to the desired content inside Microsoft 365 has been granted. Creating service accounts per content is recommended to enable faster troubleshooting and easier collaboration. As a control, the Username / Password should never be exposed directly in the code, instead using Environment Variables. The variables are encrypted on-disk, and in-memory.

The user sign-in flow option provides the typical web browser authentication experience. A user will need to be available to interact with the authentication pop-up in order to which makes this an option for interactive applications (such as the local RStudio IDE, Workbench, or an interactive Shiny app), but not applicable for scheduled content. The details are discussed in the auth vignette.

In some interactive cases it may be easier to use the device code flow where the user is prompted with a code and a link which is opened in a separate screen for logging in. For example for using a Workbench instance that was deployed without an SSL certificate. This does require interaction from the user and as such will not be applicable for scheduled content nor hosted content. The details are discussed in the auth vignette.

For Python users the Microsoft REST API is the Microsoft-developed and recommended method for accessing Microsoft 365 resources. Note that SharePoint access is using the older SharePoint 2013 REST API.

Mapping SharePoint, OneNote, or other systems as a network drive to the hosting server could be considered, using a third-party developed program such as expandrive. Note that this method also relies on application registration and it is unclear to this author how authentication is handled.

IMPORTANT NOTE: Support for addins is available only within the most recent release of RStudio (v0.99.878 or later). If you want to try out addins please be sure to download this release.

An addin can be as simple as a function that inserts a commonly used snippet of text, and as complex as a Shiny application that accepts input from the user, and later mutates a document open in RStudio. The sky is the limit!

You might be surprised to know that the Insert %in% addin is implemented entirely with R code. In fact, the R function that made this happen is located here, and its definition is simply:

The rstudioapi package allows you to interact with RStudio directly from the R code you write. You should install a recent (>= v0.5) version of the rstudioapi package to ensure you have access to all of the functions described below:

For addins in particular, a number of methods were added that allow R code to introspect and mutate the contents of a document open in RStudio. These methods are outlined below briefly, but see documentation within the rstudioapi package for more details.

Since addins are just R functions, how does addinexamples let RStudio know what functions are safe to call as addins? This is done through the registration file located at inst/rstudio/addins.dcf. Each addin you register should have the following four fields:

RStudio will automatically discover and register these addins when your package is installed. Note that you can register as many addins as you like within a single addins.dcf file, just be sure to insert a blank line between each addin that is registered.

Interactive addins are invoked by emitting a call to their function directly into the R console. For addins that display user-interface (e.g. using a Shiny application) this enables users to stop/interrupt them.

Shiny gadgets are Shiny applications which can be registered and run as addins. Typically, a Shiny Gadget provides a mechanism for interactively generating code, or modifying a document, but within this realm the possibilities are endless. This article demonstrates how you might create a simple Shiny Gadget, for more complete documentation see the following articles on the Shiny Developer Center:

The server function used for a Shiny Gadget is similar to one as provided for a regular Shiny application, except with the requirement that your application must respond to the done event. For example,

dialogViewer(): Launch your Shiny Gadget as a modal dialog within the RStudio IDE. Use this when your gadget requires a large amount of screen real estate, but is not heavy-weight enough to require a separate window.

browserViewer(): Launch your Shiny gadget in a separate window. Use this for large Shiny gadgets that require a large amount of real estate, and perhaps are more complex than applications that could fit comfortably within an RStudio modal dialog.

12:10:14.6057 => [ERROR] [UiPath.Studio.Project] [4] Failed to resolve api registration type UiPath.Core.Activities.ApiRegistration.PortableApiRegistration in assembly UiPath.System.Activities.ViewModels or UiPath.System.Activities.ViewModels.design
12:10:14.6057 => [ERROR] [UiPath.Studio.Project] [4] Failed to resolve api registration type UiPath.Testing.Activities.Portable.PortableRegisterWorkflowDesignApi in assembly UiPath.Testing.Activities or UiPath.Testing.Activities.design
12:10:15.3708 => [ERROR] [UiPath.Studio.Project] [1] Object reference not set to an instance of an object.
12:10:15.6972 => [ERROR] [UiPath.Studio.Project] [1] Object reference not set to an instance of an object.
12:10:16.9995 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System
12:10:16.9995 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System
12:10:17.9310 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System.Data
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System.DataSetExtensions
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System.Drawing
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System.Core
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System.Xml
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System.Xml.Linq
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: System
12:10:17.9327 => [WARN] [UiPath.Studio.Project] [6] Syntax Service failed to load assembly: Microsoft.VisualBasic
12:10:20.2918 => [ERROR] [UiPath.Studio.Project] [1] System.NullReferenceException: Object reference not set to an instance of an object.
at UiPath.Studio.Plugin.Workflow.Debugger.WorkflowTransform.DebugFromHere.DebugFromHereService.CanExecute(ModelItem modelItem)
at UiPath.Studio.Plugin.Workflow.Debugger.WorkflowTransform.Services.WorkflowTransformWizard2.CanStart(ModelItem modelItem) at UiPath.Studio.Plugin.Workflow.Debugger.WorkflowTransform.Services.WorkflowTransformWizardRepository.c__DisplayClass10_0.b__1() at UiPath.Studio.App.Desktop.MVVM.Commands.Command2.CanExecute(TCanExecuteParameter parameter)
12:10:20.2940 => [ERROR] [UiPath.Studio.Project] [1] System.NullReferenceException: Object reference not set to an instance of an object.
at UiPath.Studio.Plugin.Workflow.Debugger.WorkflowTransform.TestActivity.TestActivityService.CanExecute(ModelItem modelItem)
at UiPath.Studio.Plugin.Workflow.Debugger.WorkflowTransform.Services.WorkflowTransformWizard2.CanStart(ModelItem modelItem) at UiPath.Studio.Plugin.Workflow.Debugger.WorkflowTransform.Services.WorkflowTransformWizardRepository.c__DisplayClass10_0.b__1() at UiPath.Studio.App.Desktop.MVVM.Commands.Command2.CanExecute(TCanExecuteParameter parameter)
12:10:20.3813 => [WARN] [UiPath.Studio.Project] [1] Unexpected load of C:\Users\eduardo.gameiro\AppData\Local\Programs\UiPath\Studio\UiPath.NuGet.dll in default context
12:10:22.4273 => [WARN] [UiPath.Studio.Project] [11] Syntax Service failed to load assembly: UiPath.OCR.Core, Version=3.13.0.0, Culture=neutral, PublicKeyToken=null
12:10:46.4258 => [WARN] [UiPath.Studio.Project] [11] Syntax Service failed to load assembly: UiPath.Excel, Version=2.19.0.0, Culture=neutral, PublicKeyToken=null
12:10:46.5245 => [WARN] [UiPath.Studio.Project] [11] Syntax Service failed to load assembly: UiPath.Excel, Version=2.19.0.0, Culture=neutral, PublicKeyToken=null
12:10:48.0093 => [WARN] [UiPath.Studio.Project] [11] Syntax Service failed to load assembly: Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
12:10:48.8140 => [WARN] [UiPath.Studio.Project] [11] Syntax Service failed to load assembly: Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
12:10:48.8140 => [WARN] [UiPath.Studio.Project] [11] Syntax Service failed to load assembly: Microsoft.Vbe.Interop, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
12:10:48.8368 => [WARN] [UiPath.Studio.Project] [11] Syntax Service failed to load assembly: office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c

c80f0f1006
Reply all
Reply to author
Forward
0 new messages