当仪表板是本动作按钮内它显示当按下两次按钮结果(When dashboard is present

2019-10-29 14:47发布

在我的代码时,我按负载情况下按钮,它显示了当负载情况下按下按钮twice.I希望我的仪表板出现在单人click.Can仪表盘页面help.Here是我的代码

 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)

请忽略button.One更多帮助创造情景这是题外话,我可以添加一些颜色到仪表板,因为它是不是非常有吸引力。

Answer 1:

你需要设置ignoreNULL = FALSEobserveEvent

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)


文章来源: When dashboard is present inside action-button it is showing result when button is pressed twice