在闪亮的仪表板中按下 actionButton 后显示框
Display box after actionButton is pressed in a shiny dashboard
我有下面闪亮的应用程序,我希望 box
仅在按下 actionButton
时显示。否则用户会感到困惑,因为他看到的是一个没有绘图的空框。
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450),
sidebar = dashboardSidebar(minified = F, collapsed = F,
actionButton("go", "Go"),
numericInput("n", "n", 50)
),
body = dashboardBody(
box(
title = "StockPrice Reaction Around The Event Date", status = "primary", solidHeader = TRUE,
collapsible = TRUE,
plotOutput("plot"))
),
title = "DashboardPage"
)),
server = function(input, output) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
output$plot <- renderPlot({
hist(randomVals())
})
}
)
将 shinyjs::hidden()
和 shinyjs::show()
与 observeEvent()
一起使用。
您的示例现在变为:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
ui <- tags$body(
class="skin-blue sidebar-mini control-sidebar-open",
dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
# ----header----
header = dashboardHeader(
title = "Investment Advisor Monitoring - Insider Trading",
titleWidth = 450
),
# ----sidebar----
sidebar = dashboardSidebar(
minified = FALSE,
collapsed = FALSE,
actionButton("go", "Go"),
numericInput("n", "n", 50)
),
# ----body----
body = dashboardBody(
useShinyjs(), # MUST include this line
# ----hiddenbox----
shinyjs::hidden(
div(
id = "hiddenbox",
box(
title = "StockPrice Reaction Around The Event Date",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("plot")
)
)
)
)
)
)
server <- function(input, output, session) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
# ----show hiddenbox----
observeEvent(input$go, {
shinyjs::show(id = "hiddenbox")
})
output$plot <- renderPlot({
hist(randomVals())
})
}
shinyApp(ui, server)
我有下面闪亮的应用程序,我希望 box
仅在按下 actionButton
时显示。否则用户会感到困惑,因为他看到的是一个没有绘图的空框。
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450),
sidebar = dashboardSidebar(minified = F, collapsed = F,
actionButton("go", "Go"),
numericInput("n", "n", 50)
),
body = dashboardBody(
box(
title = "StockPrice Reaction Around The Event Date", status = "primary", solidHeader = TRUE,
collapsible = TRUE,
plotOutput("plot"))
),
title = "DashboardPage"
)),
server = function(input, output) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
output$plot <- renderPlot({
hist(randomVals())
})
}
)
将 shinyjs::hidden()
和 shinyjs::show()
与 observeEvent()
一起使用。
您的示例现在变为:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
ui <- tags$body(
class="skin-blue sidebar-mini control-sidebar-open",
dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
# ----header----
header = dashboardHeader(
title = "Investment Advisor Monitoring - Insider Trading",
titleWidth = 450
),
# ----sidebar----
sidebar = dashboardSidebar(
minified = FALSE,
collapsed = FALSE,
actionButton("go", "Go"),
numericInput("n", "n", 50)
),
# ----body----
body = dashboardBody(
useShinyjs(), # MUST include this line
# ----hiddenbox----
shinyjs::hidden(
div(
id = "hiddenbox",
box(
title = "StockPrice Reaction Around The Event Date",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("plot")
)
)
)
)
)
)
server <- function(input, output, session) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
# ----show hiddenbox----
observeEvent(input$go, {
shinyjs::show(id = "hiddenbox")
})
output$plot <- renderPlot({
hist(randomVals())
})
}
shinyApp(ui, server)