【发布时间】:2018-04-23 21:10:14
【问题描述】:
我希望有一个 ui 元素,例如闪亮应用程序的一个选项卡上的单选按钮“相同”或链接为不同选项卡上的 ui。可能还有其他选项卡不共享该 ui 元素。
例如,当我在下面的代码中转到摘要选项卡时,我希望在绘图选项卡中选择距离时也选择它。
library(markdown)
library(shiny)
ui <- navbarPage("Navbar!",
tabPanel("Plot", sidebarLayout(sidebarPanel(
radioButtons("yaxis1", "y-axis", c("speed"="speed", "dist"="dist"),
selected = "speed"
)),
mainPanel( plotOutput("plot") ))),
tabPanel("Summary", sidebarLayout(sidebarPanel(
radioButtons("yaxis2", "y-axis", c("speed"="speed", "dist"="dist")
)),
mainPanel(verbatimTextOutput("summary"))))
)
# Server ------------------------------------------
server <- function(input, output, session) {
output$plot <- renderPlot({ plot(cars[['speed']], cars[[input$yaxis1]]) })
output$summary <- renderPrint({ summary(cars[[input$yaxis2]]) })
}
shinyApp(ui, server)
您可以通过以下方式运行应用程序:
shiny::runGist('c8d5131c4e903817316e23e98cf088f9')
以下问题链接选项卡,但带有超链接:
R shiny build links between tabs
这也与以下内容相反:
How to use the same output binding on different tab panels in shiny
【问题讨论】:
-
你可以使用侧边栏面板吗?
-
不,因为侧边栏将被所有选项卡使用,而我仍然希望能够为每个选项卡自定义它。
-
@student 你可以在侧边栏中使用
conditionalPanel。 -
是的,你是对的。我认为条件面板会起作用。谢谢。