我有一个闪亮的应用程序,actionButton()
边栏中有 5。我希望每次用户按下按钮tabsetPanel()
时都会显示相应的按钮。重要的是默认 tabsetPanel() 应该是那个"Home"
。这就是我使用isolate()
.
#ui.r
library(shiny)
library(shinythemes)
library(plotly)
ui <- fluidPage(
theme=shinytheme("slate") ,
# App title ----
titlePanel("Tabsets"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
actionButton("ho", "Home"),
actionButton("sea", "SectionA"),
actionButton("seb", "SectionB"),
actionButton("sec", "SectionC"),
actionButton("sed", "SectionD"),
),
# Main panel for displaying outputs ----
mainPanel(
uiOutput("tabers")
)
)
)
#server.r
library(shiny)
library(shinythemes)
library(plotly)
server = function(input, output) {
observeEvent(input$ho, {
isolate(tabsetPanel(
id="tabC",
type = "tabs",
tabPanel("Global"),
tabPanel("Two Bars only here",
plotlyOutput('bars'),
plotlyOutput('bars2')
)
))
})
observeEvent(input$sea, {
tabsetPanel(
id="tabB",
type = "tabs",
tabPanel("Constituents Table Iris only here",
output$table <- DT::renderDataTable({
datatable(
iris)
})),
tabPanel("Bare only here",
plotlyOutput("bar3")
)
)
})
observeEvent(input$seb, {
tabsetPanel(
id="tabB",
type = "tabs",
tabPanel("Constituents Table Iris only here",
output$table <- DT::renderDataTable({
datatable(
iris)
})),
tabPanel("Bare only here",
plotlyOutput("bar3")
)
)
})
observeEvent(input$sec, {
tabsetPanel(
id="tabB",
type = "tabs",
tabPanel("Constituents Table Iris only here",
output$table <- DT::renderDataTable({
datatable(
iris)
})),
tabPanel("Bare only here",
plotlyOutput("bar3")
)
)
})
observeEvent(input$sed, {
tabsetPanel(
id="tabB",
type = "tabs",
tabPanel("Constituents Table Iris only here",
output$table <- DT::renderDataTable({
datatable(
iris)
})),
tabPanel("Bare only here",
plotlyOutput("bar3")
)
)
})
output$bars<-renderPlotly({
p <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
})
output$bars2<-renderPlotly({
p <- plot_ly(
x = c("gir", "ora", "mon"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
})
output$bar3<-renderPlotly({
p <- plot_ly(
x = c("gir", "ora", "mon"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
})