Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shinymanager + bs4Dash + rsconnect #59

Open
EAMI91 opened this issue Sep 7, 2020 · 5 comments
Open

shinymanager + bs4Dash + rsconnect #59

EAMI91 opened this issue Sep 7, 2020 · 5 comments

Comments

@EAMI91
Copy link

EAMI91 commented Sep 7, 2020

I am having some trouble figuring out what the problem should be here. Let me explain. I did an app that works perfectly in my computer and in shinyapps.io what is very strange is that returning the auth values after login are NULL when running the app in Rstudio Connect. When I replace bs4DashPage into a fluidPage or even a dashboardPage from the package shinydashboard, it works perfectly. I can't understand why using the package bs4Dash won't work only on Rstudio Connect. I would appreciate some ideas. Here is an example of my code.

library(shiny)
library(shinymanager)
library(bs4Dash)

ui <-     bs4DashPage(navbar = bs4DashNavbar(),
            sidebar = bs4DashSidebar(
              sidebarMenu(
                menuItem(text = "Crear",tabName = "uno")
              )
            ),
            body =  bs4DashBody(
              tabItems(
                tabItem(tabName = "uno",
                        verbatimTextOutput("auth_output"))
              )
            )
)

# Wrap your UI with secure_app
ui <- secure_app(ui,enable_admin = T)


server <- function(input, output, session) {
  
  # call the server part
  # check_credentials returns a function to authenticate users
  res_auth <- secure_server(
    check_credentials = check_credentials(db = "###.sqlite", passphrase = "###")
  )
  
  output$auth_output <- renderPrint({
    reactiveValuesToList(res_auth)
  })
  
  # your classic server logic
  
}

shinyApp(ui, server)
@EAMI91 EAMI91 changed the title shinymanagaer + bs4Dash + rsconnect shinymanager + bs4Dash + rsconnect Sep 7, 2020
@bthieurmel
Copy link
Contributor

Hi,

Because I can't test on RStudio Connect, it's very difficult to help you and try to find a solution... Can you have some errors in the R console and the web console ?

@bthieurmel
Copy link
Contributor

Is the application working on Rstudio Connect using bs4Dash but removing shinymanager authentification ?

@FlavioLeccese92
Copy link

Hello everyone, I'm facing the same issue and I have found a possible reason for this behaviour (not a solution unluckily).

The key-point is that the information in session$clientData$url_search is not carried over when passing from "request" in secure_app to all the observed events in secure_server. For instance;

  • query is pupulated correctly

    function(request) {
    query <- parseQueryString(request$QUERY_STRING)
    token <- query$token
    admin <- query$admin
    language <- query$language

  • token_start gives a blank list

    token_start <- isolate(getToken(session = session))

  • If I try to catch information as it is in the server

server <- function(input, output, session) {
    observeEvent(session, {
        print("print session$clientData$url_search")
        print(session$clientData$url_search)
    })
}

it gives a blank list.

I can confirm that simple shiny apps work correctly even when deployed on rstudio connect, as well as bs4dash is working correctly locally. I did some research and found that bs4dash refresh the URL when it does not contain a so-called WorkerId
open issue here, quoting:

var workerId = $('base').attr('href');
  // ensure that this code does not locally
  if (typeof workerId != "undefined") {
    var pathname = window.location.pathname;
    var newpath = pathname + workerId;
    window.history.replaceState( {} , 'newpath', newpath);
  }

You cannot comment last line because it is needed to use the "same session".
Is there an alternative way to pass token info (in a safe way) through all the parts of code?
Thank you in advance for your work, I think that having it working in bs4dash+connect will give a great boost to this package!

@FlavioLeccese92
Copy link

FlavioLeccese92 commented Nov 2, 2020

@EAMI91
I found a temporary (but satisfying) solution on this issue. This is how I solved:
The problem, as I spotted, is on the shinymanager but on bs4dash side. In particular the chunk which redirects the page to an url with something like "/_w_123456" that is a workerId (necessary for apps on shinyapps.io but, as it seems to me, not on rstudio connect):

var workerId = $('base').attr('href');
  // ensure that this code does not locally
  if (typeof workerId != "undefined") {
    var pathname = window.location.pathname;
    var newpath = pathname + workerId;
    window.history.replaceState( {} , 'newpath', newpath);
  }

You can find that part of code stored into pathtoRlib\bs4Dash\bs4Dash-0.2.0\bs4Dash.js .

  1. Simply comment like this and save the file
//window.history.replaceState( {} , 'newpath', newpath);
  1. In the App, instead of using
library(bs4Dash)

load it from a given personal path (where you have saved a fixed copy of the whole package and it is reachable by the connect server, maybe the working directory of the app itself):

library("bs4Dash", lib.loc="//dir_containing_fixed_bs4dash")
  1. Deploy as usual, you will be able to have shinymanager working as it has (magnificently)

Let me know, in case you read this, if it works.

@aljrico
Copy link

aljrico commented Dec 28, 2020

Hi!

I am trying to deploy a Shiny App that, among other things, is capable of reading GET requests. This is possible if the user adds parameters to the address, like https://myapp.shinyapps.io/?param1=4234&param2=2342

Everything works perfectly until I moved the shinydashboard bits to bs4Dash. Whenever the user tries to input those parameters, the address gets quickly updated to https://myapp.shinyapps.io/w_88a98847/. So the request can't be captured.

Commenting out that line, as you mention, would be captured by shinyapps.io so that gets solved? Would that create other potential issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants