将navbarTab名称返回到server.r(Return navbarTab name to server.r)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
将navbarTab名称返回到server.r(Return navbarTab name to server.r)

我希望将所选navbarPage选项卡(顶层)的名称(或其他唯一标识符)返回到server.r文件以进行条件显示。

下面是一个最小的例子,其目标是使选定的navbarPage选项卡名称(“NavTab1”或“NavTab2”)可用于verbatimText。

ui.r:

navbarPage("Navbar", tabPanel("NavTab1", br(), verbatimTextOutput("text"), tabsetPanel(type="tabs", tabPanel("Plot 1", plotOutput("plot1") ) ) ), tabPanel("NavTab2", br(), tabsetPanel(type="tabs", tabPanel("Plot 2", plotOutput("plot2") ) ) ) )

server.r:

function(input, output, session) { output$plot1 <- renderPlot({ plot(x=runif(10), col="blue") }) output$plot2 <- renderPlot({ plot(x=runif(1000), col="red") }) output$text <- renderText({ RETURN NAVTAB NAME }) }

navbarPage文档使它看起来像这是可能的,但没有我尝试过的id或value的组合都有效。 任何帮助赞赏。

I would like to have the name (or some other unique identifier) from the selected navbarPage tab (top level) be returned to the server.r file for conditional display.

A minimal example is below, where the goal is to make the selected navbarPage tab name ("NavTab1" or "NavTab2") available to the verbatimText.

ui.r :

navbarPage("Navbar", tabPanel("NavTab1", br(), verbatimTextOutput("text"), tabsetPanel(type="tabs", tabPanel("Plot 1", plotOutput("plot1") ) ) ), tabPanel("NavTab2", br(), tabsetPanel(type="tabs", tabPanel("Plot 2", plotOutput("plot2") ) ) ) )

server.r:

function(input, output, session) { output$plot1 <- renderPlot({ plot(x=runif(10), col="blue") }) output$plot2 <- renderPlot({ plot(x=runif(1000), col="red") }) output$text <- renderText({ RETURN NAVTAB NAME }) }

The navbarPage docs make it look like this is possible, but none of the combinations of id or value that I've tried have worked. Any help appreciated.

最满意答案

您可以通过设置navbarPage()的id参数并在服务器中引用input$id来访问当前导航栏选项卡的名称。 下面显示了一个非常简单的例子。

library(shiny) shinyApp( ui=navbarPage("Navbar",id="navbar", tabPanel("NavTab1", verbatimTextOutput("current_tab_view1")), tabPanel("NavTab2", verbatimTextOutput("current_tab_view2")) ), server = function(input,output,session){ output$current_tab_view1 <- renderText(input$navbar) output$current_tab_view2 <- renderText(input$navbar) } )

结果

navbareg

You can access the name of the current navbar tab selected by setting the id argument of the navbarPage() and referencing that input$id in your server. A very minimal example of this is shown below.

library(shiny) shinyApp( ui=navbarPage("Navbar",id="navbar", tabPanel("NavTab1", verbatimTextOutput("current_tab_view1")), tabPanel("NavTab2", verbatimTextOutput("current_tab_view2")) ), server = function(input,output,session){ output$current_tab_view1 <- renderText(input$navbar) output$current_tab_view2 <- renderText(input$navbar) } )

result

navbareg

更多推荐

本文发布于:2023-04-13 12:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/038f9995780e6e4b1454001fbf66d5db.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   navbarTab   Return   server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!