如何解决如何获取Shiny App的当前URL?
当我在RStudio上运行一个闪亮的应用程序时,我的应用程序将运行,并且URL如下所示:
Listening on http://127.0.0.1:4991
但是每次我再次运行该应用程序时,端口都会改变,我想知道是否有一种方法可以获取作为变量或类似内容的url。我的意思是,每次运行该应用程序时,我都希望获取URL并将其保存在变量中。
谢谢
解决方法
您可以使用以下选项指定端口:
#example: https://shiny.rstudio.com/articles/basics.html
options(shiny.host = '0.0.0.0')
options(shiny.port = 8888)
ui <- fluidPage(
# App title ----
titlePanel("Hello Shiny!"),# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Slider for the number of bins ----
sliderInput(inputId = "bins",label = "Number of bins:",min = 1,max = 50,value = 30)
),# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
plotOutput(outputId = "distPlot")
)
)
)
# Define server logic required to draw a histogram ----
server <- function(input,output) {
# Histogram of the Old Faithful Geyser Data ----
# with requested number of bins
# This expression that generates a histogram is wrapped in a call
# to renderPlot to indicate that:
#
# 1. It is "reactive" and therefore should be automatically
# re-executed when inputs (input$bins) change
# 2. Its output type is a plot
output$distPlot <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x),max(x),length.out = input$bins + 1)
hist(x,breaks = bins,col = "#75AADB",border = "white",xlab = "Waiting time to next eruption (in mins)",main = "Histogram of waiting times")
})
}
shinyApp(ui,server)
,
您可以使用session$clientData
获取该网址:
library(shiny)
ui <- basicPage()
server <- function(input,output,session){
observe({
print(reactiveValuesToList(session$clientData))
})
}
shinyApp(ui,server)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。