Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • a78cb8f
  • /
  • server
  • /
  • Shinychat.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:99bf95e5a7c53481c8c803858cc95cf8ddcdbfbf
directory badge
swh:1:dir:b4f135b203230666f5e14abbaf58604b20e67ee4

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Shinychat.R
#https://shiny.rstudio.com/gallery/chat-room.html


# Create a spot for reactive variables specific to this particular session
sessionVars <- reactiveValues(username = "")

# Track whether or not this session has been initialized. We'll use this to
# assign a username to unininitialized sessions.
init <- FALSE

# When a session is ended, remove the user and note that they left the room.
session$onSessionEnded(function() {
  isolate({
    vars$users <- vars$users[vars$users != sessionVars$username]
    vars$chat <- c(vars$chat, paste0(linePrefix(),
                                     tags$span(class="user-exit",
                                               sessionVars$username,
                                               "left the room.")))
  })
})

# Observer to handle changes to the username
observe({
  # We want a reactive dependency on this variable, so we'll just list it here.
  input$user

  if (!init){
    # Seed initial username
    sessionVars$username <- ifelse(userId == "", paste0("User", round(runif(1, 10000, 99999))) , paste0(userId, round(runif(1, 10000, 99999))))

    isolate({
      vars$chat <<- c(vars$chat, paste0(linePrefix(),
                                        tags$span(class="user-enter",
                                                  sessionVars$username,
                                                  "entered the room.")))
    })
    init <<- TRUE

  } else{
    # A previous username was already given
    isolate({
      if (input$user == sessionVars$username || input$user == ""){
        # No change. Just return.
        return()
      }

      # Updating username
      # First, remove the old one
      vars$users <- vars$users[vars$users != sessionVars$username]

      # Note the change in the chat log
      vars$chat <<- c(vars$chat, paste0(linePrefix(),
                                        tags$span(class="user-change",
                                                  paste0("\"", sessionVars$username, "\""),
                                                  " -> ",
                                                  paste0("\"", input$user, "\""))))

      # Now update with the new one
      sessionVars$username <- input$user
    })
  }
  # Add this user to the global list of users
  isolate(vars$users <- c(vars$users, sessionVars$username))
})

# Keep the username updated with whatever sanitized/assigned username we have
observe({
  updateTextInput(session, "user",
                  value=sessionVars$username)
})

# Keep the list of connected users updated
output$userList <- renderUI({
  tagList(tags$ul( lapply(vars$users, function(user){
    return(tags$li(user))
  })))
})

# Listen for input$send changes (i.e. when the button is clicked)
observe({
  if(input$send < 1){
    # The code must be initializing, b/c the button hasn't been clicked yet.
    return()
  }
  isolate({
    # Add the current entry to the chat log.
    if(input$entry != "")
      vars$chat <<- c(vars$chat,
                      paste0(
                        linePrefix(),
                        tags$span(class = "username",
                                  tags$abbr(title = Sys.time(), sessionVars$username)),
                        ": ",
                        tagList(input$entry)
                      ))

  })
  # Clear out the text entry field.
  updateTextInput(session, "entry", value="")
})

# Dynamically create the UI for the chat window.
output$chat <- renderUI({
  if (length(vars$chat) > 500){
    # Too long, use only the most recent 500 lines
    vars$chat <- vars$chat[(length(vars$chat)-500):(length(vars$chat))]
  }
  # Save the chat object so we can restore it later if needed.
  if(userId == "")
    saveRDS(vars$chat, "./chat/chat.Rds")
  else
    saveRDS(vars$chat, "/root/MA_Trix_App/chat/chat.Rds")


  # Pass the chat log through as HTML
  HTML(vars$chat)
})

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API