2

I wonder if I can create a shiny app (something similar to excel spreadsheet) that I can authorize multiple users to log in (like using shinyapp.io) to edit/input simultaneously? The reason I want to use shiny rather than only excel spreadsheet is because I might add more features (such as statistical estimation, visualization, etc.) based on the data uploaded by multiple users using R.

Look forward to any suggestions/advice Thanks!

Dashh
  • 43
  • 5
  • yes its possible if you put the reactivevalues outside the server function: See the code of this example: https://shiny.rstudio.com/gallery/chat-room.html – Tonio Liebrand Aug 16 '18 at 20:10

1 Answers1

2

I found the following pattern working for me: Create a reactiveVal object outside the server and then access/update it in the app. Here, I wrote a wrapper for getting and appending massages to a chat. (code below)

However, I think this pattern only works if all users share the same R session and the data will be lost if the current R session ends (all users disconnect). Therefore, you might want to look into this article to get a hang of persistent storage methods. Also, look at the documentation of reactiveFileReader for a more conveniet way of accessing files.

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      textInput("msg", "Message", placeholder = "type a message in the chat"),
      actionButton("submit", "submit")
    ),
    mainPanel(
      verbatimTextOutput("text")
    )
  )
)

createChat <- function(initVal) {
  chat_text <- reactiveVal(initVal)
  list(
    get = function(){ chat_text() },
    append = function(val) {
      chat_text(paste0(isolate(chat_text()), "\n", val))
    }
  )
}

myChat <- createChat("## This is a chat ##\n")

server <- function(input, output) {
  observeEvent(input$submit, {
    myChat$append(input$msg)
  })
  output$text <- renderText(myChat$get())
}

shinyApp(ui = ui, server = server)
Gregor de Cillia
  • 7,397
  • 1
  • 26
  • 43