shiny app for multiple users to edit

拈花ヽ惹草 提交于 2019-12-10 12:07:09

问题


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!


回答1:


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)


来源:https://stackoverflow.com/questions/51881472/shiny-app-for-multiple-users-to-edit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!