条件情节shinydashboard

时间:2017-05-06 23:19:26

标签: conditional plotly shinydashboard

我想知道为什么(在下面的代码中)当我点击复选框"图表"?时,图表不显示下面是代码示例。我还想知道是否可以使用conditionalPanel而不是renderUI来做同样的事情?

library(shinydashboard)
library(shiny)
library(plotly)
library(ggplot2)


# Can set box height from environment var

useboxheight <- Sys.getenv("USE_BOX_HEIGHT")

if (tolower(useboxheight) == "true") {

  row1height <- 300

  row2height <- 240

  row3height <- 110

} else {

  row1height <- row2height <- row3height <- NULL

}

body <- dashboardBody(

  fluidRow(

    box(

      title = "Box title",

      status = "primary",

      plotOutput("plot1", height = 240),

      height = row1height

    ),

    uiOutput("ui")

  ),



  # Boxes with solid headers

  fluidRow(

    box(

      title = "Title 1", width = 4, solidHeader = TRUE, status = "primary",

      height = row2height,

      sliderInput("orders", "Orders", min = 1, max = 500, value = 120),

      radioButtons("fill", "Fill", inline = TRUE,

                   c(None = "none", Blue = "blue", Black = "black", red = "red")

      )

    ),

    box(

      title = "Title 2",

      width = 4, solidHeader = TRUE,

      height = row2height

    ),

    box(

      title = "Title 3",

      width = 4, solidHeader = TRUE, status = "warning",

      height = row2height,

      selectInput("spread", "Spread",

                  choices = c("0%" = 0, "20%" = 20, "40%" = 40, "60%" = 60, "80%" = 80, "100%" = 100),

                  selected = "60"

      )

    )

  ),

  # Solid backgrounds

  fluidRow(

    box(

      width = 4,

      height = row3height,

      background = "black",

      "A box with a solid black background"

    ),

    box(

      title = "Title 5",

      width = 4,

      height = row3height,

      background = "light-blue",

      "A box with a solid light-blue background"

    ),

    box(

      title = "Title 6",

      width = 4,

      height = row3height,

      background = "maroon",

      "A box with a solid maroon background"

    )



  )

)



ui <- dashboardPage(

  dashboardHeader(title = "Row layout"),

  dashboardSidebar(checkboxGroupInput(inputId="Graph", label = h4("Graph print"), 
                                      choices = list("graph" = "graph"),selected = NULL)),

  body

)



server <- function(input, output) {



  set.seed(122)

  histdata <- rnorm(500)



  output$plot1 <- renderPlot({

    if (is.null(input$orders) || is.null(input$fill))

      return()



    data <- histdata[seq(1, input$orders)]

    color <- input$fill

    if (color == "none")

      color <- NULL

    hist(data, col = color)

  })


  output$ui <- renderUI({

    check1 <- input$Graph == "graph"

    if(length(check1)==0){check1 <- F}

    if(check1){
      box(

        status = "warning",

        plotOutput("plot1", height = 240),

        height = row1height
      )
    }
    else{return(NULL)}
  })


}


shinyApp(ui, server)

干杯

戴夫

1 个答案:

答案 0 :(得分:0)

我会开始看看output$plot1 <- renderPlot({括号下面发生的事情。确保您的条件函数是合理的。

您的renderUI代码也是如此。