编辑:要获取有关单击的选项卡的信息,请查看:?tabsetPanel
您会看到您可以为面板指定一个 id。
因此 tabsetPanel(id="tabs",...) 将使您能够使用 input$tabs 在服务器端跟踪选定的 tabpanel。
参见下面的示例:(基于https://shiny.rstudio.com/articles/tabsets.html)
library(shiny)
ui <- shinyUI(pageWithSidebar(
# Application title
headerPanel("Tabsets"),
# Sidebar with controls to select the random distribution type
# and number of observations to generate. Note the use of the br()
# element to introduce extra vertical spacing
sidebarPanel(
radioButtons("dist", "Distribution type:",
list("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")),
br(),
sliderInput("n",
"Number of observations:",
value = 500,
min = 1,
max = 1000)
),
# Show a tabset that includes a plot, summary, and table view
# of the generated distribution
mainPanel(
tabsetPanel(id = "tabs",
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Visited Tabs", tableOutput("table"))
)
)
))
# Define server logic for random distribution application
server <- shinyServer(function(input, output, session) {
global <- reactiveValues(visitedTabs = c())
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The renderers defined
# below then all use the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm)
dist(input$n)
})
observe({
input$tabs
isolate({
userTabInfo <- paste0(" selected: ",input$tabs)
print(userTabInfo)
global$visitedTabs = c(global$visitedTabs, userTabInfo)
})
})
# Generate a plot of the data. Also uses the inputs to build the
# plot label. Note that the dependencies on both the inputs and
# the 'data' reactive expression are both tracked, and all expressions
# are called in the sequence implied by the dependency graph
output$plot <- renderPlot({
dist <- input$dist
n <- input$n
hist(data(),
main=paste('r', dist, '(', n, ')', sep=''))
})
# Generate a summary of the data
output$summary <- renderPrint({
str(session$userData)
# session$user
})
# Generate an HTML table view of the data
output$table <- renderTable({
data.frame(global$visitedTabs)
})
})
shinyApp(ui, server)
关于 IP:我知道大约 4-5 个代码 sn-ps 来获取 IP,它们都使用 JSS 或 XSS 风格,你怎么称呼它:) 我同意这应该是可能的,但既然人们已经问过 3 -4 年前,我不确定这是否真的是闪亮团队的意识问题。希望标签跟踪无论如何都有帮助。如果你喜欢我可以添加 JS sn-p 再次获取 IP。