2017-05-06 18 views
0

我想知道为什么(在下面的代码中)当我点击复选框“graph”时图不显示?以下是代码示例。我也想知道是否有可能使用conditionalPanel而不是renderUI来做同样的事情?条件图shinydashboard

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) 

干杯

戴夫

回答

0

我将开始我考虑看看的output$plot1 <- renderPlot({托架下面会发生什么。确保你的条件函数是健全的。

同样适用于您的renderUI代码。