datastorm-open/shinymanager

Flexdashboard

ffalcolini opened this issue · 16 comments

Hi!

Is it possible to use shinymanager with flexdashboard?
If so, could I have an example?

Thanks a lot for the cooperation

I am also interested in this. Thanks

I have made several attempts, but I cannot use shiny manager with flex dashbaord.

If we suppose we have this flexdashboard code:

---
title: "Multiple Pages"
output: flexdashboard::flex_dashboard
---

Page 1
===================================== 
    
### Chart 1
    

### Chart 2


   
Page 2
=====================================     

### Chart 1
    
    
### Chart 2

how should I put shinymanager in the code?

Thanks a lot for your cooperation

I am also interested in this. Did you figurate out how to do it?

Perhaps some answer on #25 ?

First, you can't use shinymanager in flexdashboard without the option runtime: shiny, and so document must be deployed using shiny-server

This is one solution :

---
title: "Old Faithful Eruptions"
output: 
  flexdashboard::flex_dashboard:
    css: inst/assets/styles-auth.css
runtime: shiny
---

You need to add a css file with at least this content (here in inst/assets/styles-auth.css) :

.panel-auth {
  position: fixed;
  top:0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #FFF;
  opacity: 1;
  z-index: 99997;
  overflow-x: hidden;
  overflow-y: scroll;
}

Then in global chunk, load shinymanager and define credentials :

```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
library(shinymanager)
data(faithful)

# define some credentials (you can also use sqlite database)
credentials <- data.frame(
  user = c("shiny", "shinymanager"),
  password = c("azerty", "12345"),
  stringsAsFactors = FALSE
)
```

Finally, anywhere, call the two modules :

```{r}
auth_ui(id = "auth")

auth <- callModule(
    module = auth_server,
    id = "auth",
    check_credentials = check_credentials(credentials) # data.frame
    # check_credentials = check_credentials("path/to/credentials.sqlite", passphrase = "supersecret") # sqlite
)
```

Full example :


---
title: "Old Faithful Eruptions"
output: 
  flexdashboard::flex_dashboard:
    css: inst/assets/styles-auth.css
runtime: shiny
---

```{r global, include=FALSE}
# load data in 'global' chunk so it can be shared by all users of the dashboard
library(datasets)
library(shinymanager)
data(faithful)

# define some credentials (you can also use sqlite database)
credentials <- data.frame(
  user = c("shiny", "shinymanager"),
  password = c("azerty", "12345"),
  stringsAsFactors = FALSE
)
```

Column {.sidebar}
-----------------------------------------------------------------------

Waiting time between eruptions and the duration of the eruption for the
Old Faithful geyser in Yellowstone National Park, Wyoming, USA.

```{r}
selectInput("n_breaks", label = "Number of bins:",
            choices = c(10, 20, 35, 50), selected = 20)

sliderInput("bw_adjust", label = "Bandwidth adjustment:",
            min = 0.2, max = 2, value = 1, step = 0.2)
```

Column
-----------------------------------------------------------------------

### Geyser Eruption Duration

```{r}

renderPlot({
  hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
       xlab = "Duration (minutes)", main = "Geyser Eruption Duration")

  dens <- density(faithful$eruptions, adjust = input$bw_adjust)
  lines(dens, col = "blue")
})


auth_ui(id = "auth")

auth <- callModule(
    module = auth_server,
    id = "auth",
    check_credentials = check_credentials(credentials) # data.frame
    # check_credentials = check_credentials("path/to/credentials.sqlite", passphrase = "supersecret") # sqlite
)
```

I tested the last solution of @bthieurmel but it does not work. It just shows an empty flexdashboard.
Do you have any ideas why it does not show anything?

Hi,

I test this solution, it work,
but when I run this on shiny, I saw that the app is running, and do not wait the login.

Any idea?

How to put timeout=0?

Thanks so much @bthieurmel. This solution worked for me. Do you know if it's possible to utilize admin mode with this flexdashboard use?

I see thank you. Is there anyway to make the shiny manager more secure considering that you can "overpass" the user authentication in the developer's console? Alternatively, is there any package or module that could create a secure authentication for a flexdashboard?

Not a problem, I have been hesitant to do a shinydashboard because I am a novice, but it seems like it's the route I need to go with ultimately. Thanks so much for doing that research and for the help.