【发布时间】:2019-08-28 10:26:55
【问题描述】:
我有一个闪亮的应用程序,边栏中有 5 actionButton()。我希望每次用户按下按钮时都会显示相应的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"
)
})
【问题讨论】:
标签: r shiny action-button