0

I'll operate rshiny app in win10 as server

Running Rshiny in a win10 environment and running the server with the code shown in the example below,

I want to receive and store the information of the client connecting with the assigned host ip.

what should I do if I want to get the username of another win10 client or client's Computername?

The Sys.getenv() function like the code below only returns the server's username...

shinydashboard_test.R

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title="Test"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
      menuItem("Widgets", tabName = "widgets", icon = icon("th"))
    )
  ),
  dashboardBody(
    
    tabItems(
      tabItem(tabName="dashboard",
              fluidRow(
                box(plotOutput("plot1",height=250)),
                box(
                  title="Contorls",
                  sliderInput("slider","Number of ovservations",1,100,50)
                  )
                )
              ),
      tabItem(tabName="widgets",
              h2("Widgets tab Content")
              )
      )
    )
)
server <- function(input,output,session){
  set.seed(122)
  histdata <- rnorm(500)
  
  ip <- session$request$REMOTE_ADDR
  cat("ip:",ip,"time : ",as.character(Sys.time()),"user :", as.character(Sys.getenv("USERNAME")),"\n")
  
  output$plot1 <- renderPlot({
    data <- histdata[seq_len(input$slider)]
    hist(data)
  })
}
shinyApp(ui,server)

runShiny.R

require(shiny)

folder_address="C:/shinydashboard_test.R"
x <- system("ipconfig",intern=TRUE)
z <- x[grep("IPv4",x)]
ip <- gsub(".*?([[:digit:]])","\\1",z)
print(paste0("the Shiny Web application runs on: http://",ip,":8080/"))

runApp(folder_address,launch.browser = TRUE,port=8080,host=ip)
JAIL
  • 65
  • 3
  • (1) `Sys.getenv` is only going to tell you something about the local user/computer, not the remote. (2) Didn't your [previous question](https://stackoverflow.com/q/62546575/3358272) (and my answer to it) give you what you need here? (Namely: `session$username`) – r2evans Jun 24 '20 at 06:36
  • session$username is only return NULL in my environment.. is there another way?? – JAIL Jun 24 '20 at 06:41
  • 1
    Are you deploying it to a server? – r2evans Jun 24 '20 at 06:43
  • 2
    session$username is only available with the pro version of the server, not the open source version – Waldi Jun 24 '20 at 06:46
  • No.. It just for Internal network in my company. – JAIL Jun 24 '20 at 06:46
  • Thanks, @Waldi, that's perhaps the key part that I didn't know and JAIL needs. – r2evans Jun 24 '20 at 06:50

1 Answers1

0

Does Sys.info()[['user']] give you what you want?

Limey
  • 10,234
  • 2
  • 12
  • 32