首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在rshiny获取窗口用户名

问如何在rshiny获取窗口用户名
EN

Stack Overflow用户
提问于 2020-06-24 14:23:39
回答 1查看 99关注 0票数 0

我将在win10中操作闪亮的应用程序作为服务器

在win10环境下运行Rshiny,并使用以下示例中的代码运行服务器。

我想接收并存储与分配的主机ip连接的客户端的信息。

如果我想要获取另一个win10客户端的用户名或客户端的计算机名,我应该怎么做?

下面的代码所示的Sys.getenv()函数只返回服务器的用户名...

shinydashboard_test.R

代码语言:javascript
复制
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

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2020-06-24 14:36:12

Sys.info()[['user']]给你想要的东西了吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62548928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档