在我的代码中,当我按下加载方案按钮时,它会在两次按下加载方案按钮时显示仪表板页面。我希望我的仪表板可以单击一下,任何人都可以帮忙。这是我的代码
library("shiny")
library("shinydashboard")
ui <- fluidPage(
actionButton("create_scenario", "Create Scenario"),
actionButton("load_scenario","load scenario"),
uiOutput("input"),
uiOutput("inputs")
)
server <- function(input, output,session) {
observeEvent(input$create_scenario,{
output$input <- renderUI({
textInput("txtInput","Enter Scenario Name","Enter name as scenario
(number of senario created +1)")
})
})
observeEvent(input$load_scenario,{
output$inputs <- renderUI({
# textInput("txtInput","Enter Scenario Name","Enter name as scenario
#(number of senario created +1)")
dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
))))
} )
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
})
}
shinyApp(ui, server)
请忽略“创建方案”按钮。由于主题不是很吸引人,我可以为仪表板添加一些颜色吗?
答案 0 :(得分:0)
您需要为ignoreNULL = FALSE
设置observeEvent
:
library("shiny")
library("shinydashboard")
ui <- fluidPage(
actionButton("create_scenario", "Create Scenario"),
actionButton("load_scenario","load scenario"),
uiOutput("input"),
uiOutput("inputs")
)
server <- function(input, output,session) {
observeEvent(input$create_scenario, {
output$input <- renderUI({
textInput("txtInput","Enter Scenario Name","Enter name as scenario
(number of senario created +1)")
})
})
observeEvent(input$load_scenario, {
output$inputs <- renderUI({
# textInput("txtInput","Enter Scenario Name","Enter name as scenario
#(number of senario created +1)")
dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
))))
})
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}, ignoreNULL = FALSE)
}
shinyApp(ui, server)