表未显示在mainPanel的选项卡中 - Shiny

时间:2016-10-13 02:31:21

标签: r shiny shiny-server lidar

我正在尝试在主面板中显示一个表但没有显示任何内容,我没有收到任何错误消息,它只是空白。如果有人能帮我解决这个问题,我会非常感激。提前谢谢!

ui.R

shinyUI(fluidPage(

  titlePanel(title=h2("Deteccao de arvores individuais de LiDAR em Shiny App - R", align="center")),

  headerPanel(title=h4("Defina seus parametros e preferencias")),

  sidebarLayout(
    sidebarPanel(
      fileInput('layer', 'Select the CHM.asc file', multiple=FALSE, accept='asc', width = "350px"),
      textInput("hmin", "Select the minimum height for trees (m)", value="", width = "350px"),
      selectInput("fws", "Select the size of windows to find trees", choices = c("3x3"= (sws<-3), "5x5"= (sws<-5), "7x7"= (sws<-7)), width = "350px"),
      wellPanel(checkboxInput("checkbox", "Would you like to apply the smoothing model for canopy?", value = FALSE, width = "350px"), uiOutput("conditionalInput")),
      actionButton("action", "RUN!")
     # selectInput("color", "Define the CHM color", "green"), plotOutput("chmcol")),
     # wellPanel(checkboxInput("checkp1", "Plot CHM in 3D", value=FALSE, width="350px", uiOutput("chm3D"))),
     # wellPanel(checkboxInput("checkp2", "Plot individual trees in 3D", value = "350px", uiOutput("arv3D")))


      ),

  mainPanel(
    tabsetPanel(type="tab",
                tabPanel("Visualization of CHM", plotOutput("mapPlot")),
                tabPanel("Summary of LiDAR metrics", tableOutput("sumy")),
                tabPanel("Profile of height model"), #histograma de densidade
                tabPanel("Individual trees detected - Model 2D of CHM"),
                tabPanel("Individual trees detected - Model 3D of CHM"),
                tabPanel("Individual trees detected - Model 3D of Single trees")

                 )


    ))
  ))

server.R

if(Sys.getenv('SHINY_PORT') == "") options(shiny.maxRequestSize=10000*1024^2)

shinyServer(function(input, output) {



  output$mapPlot <- renderPlot({

    inFile <- input$layer

    if (is.null(inFile))
      return(NULL)

    data <- raster(inFile$datapath)

    plot(data)

  })

    output$conditionalInput <- renderUI({


    if(input$checkbox){
      selectInput("sws", "Select the size of the smoothing window for trees", choices = c("3x3"= (sws<-3), "5x5"= (sws<-5), "7x7"= (sws<-7)), width = "350px")
    }
  })


  output$sumy <- renderTable({

    input$act

      if(is.null(input$act))
        return(NULL)

      else
        isolate({
        Arv.List <- FindTreesCHM(output$mapPlot, input$sws, input$hmin)
        sum <- summary(Arv.List)
        head(sum)
        })
  })

  })

1 个答案:

答案 0 :(得分:1)

错误似乎是由您的文件产生的:

FindTreesCHM(raster("LiDAR_CONIFERAS_chm.asc"), 3, 3) 
Error in `colnames<-`(`*tmp*`, value = c("x", "y", "height")) : 
  length of 'dimnames' [2] not equal to array extent

尽管普通R中也存在错误,但这就是我写反应性闪亮部分的方法:

  data <- observe({raster(inFile$datapath)})
  output$mapPlot <- renderPlot({plot(data())})
  Arvlist <- eventReactive(input$action, {isolate(FindTreesCHM(data(), input$sws, input$hmin))})
  output$sumy <- renderTable({summary(Arvlist())})