我希望将所选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) } )结果
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
更多推荐
发布评论