2017-04-26 4 views
1

내 R 반짝이는 응용 프로그램에서 tabBox에 3 개의 탭을 만들었지 만 세 번째 탭은 나타나지 않습니다. 세 번째 탭, "시각화"에 checkBoxGroupInput 및 ggplots을 지정하고 싶습니다.ShinyDashboard - 제 3의 탭이 표시되지 않습니다

library(shiny) 
library(shinydashboard) 
library(devtools) 
library(leaflet) 
library(DT) 
library(ggplot2) 
library(dplyr) 

r_colors <- rgb(t(col2rgb(colors())/255)) 
names(r_colors) <- colors() 

plotdata <- read.csv("RShinyCoral.csv") 
colnames(plotdata) <- c("Year1", "RLIMona", "Year2", "RLICatalina", "Year3", "RLILaParguera1998", "Year4", "RLILAPARGUERA2004") 
parguera <- read.csv("RShinyCoral.csv") 
parguera <- select(parguera, 5:8) 
colnames(parguera) <- c("Year", "1998 Expedition", "Year", "2004 Expedition") 
monaisland <- read.csv("RShinyCoral.csv") 
monaisland <- select(monaisland, 1:2) 
colnames(monaisland) <- c("Year", "Mona Island RLI") 
islacatalina <- read.csv("RShinyCoral.csv") 
islacatalina <- select(islacatalina, 3:4) 
colnames(islacatalina) <- c("Year", "Isla Catalina RLI") 

ui <- dashboardPage(

       dashboardHeader(
    title = "NOAA Puerto Rico Coral Luminescence (RLI, 5-year Running Average, 1730 - 1992)" 
          ), 
       dashboardSidebar(disable = TRUE), 
       dashboardBody(
           fluidRow(
             tabBox(
               title = "", width = 12, id = "tabset1", 
                 tabPanel("Reef Locations", leafletOutput("mymap")), 
                 tabPanel("Data Tables", 
                    tags$a(href = "https://www.google.com/", "Click for Source Data"), 
                    p(), 
                    fluidRow(
                      column(3, 
                        actionButton("laparguera", "La Parguera Data"), 
                        actionButton("mona", "Mona Island Data"), 
                        actionButton("isla", "Isla Catalina Data") 
                        ) 
                      ), 
                    fluidRow(column(12, DT::dataTableOutput('tbl')), 
                    fluidRow(column(12, plotOutput("plot1")), 
                 tabPanel("Visualize", 
                    fluidRow( 
                      column(9, 
                        actionButton("visualize", "Add to Plot"), 
                    fluidRow(
                    column(9, 
                      checkboxGroupInput("checkbox", label = NULL, 
                          c("La Parguera", "Mona Island", "Isla Catalina"))) 
      ))))))))))) 

server <- function(input, output) { 

    observeEvent(input$laparguera, { 
    output$tbl <- DT::renderDataTable(DT::datatable(parguera, options = list(pagelength = 25))) 
    }) 
    observeEvent(input$mona, { 
    output$tbl <- DT::renderDataTable(DT::datatable(monaisland, options = list(pagelength = 25))) 
    }) 
    observeEvent(input$isla, { 
    output$tbl <- DT::renderDataTable(DT::datatable(islacatalina, options = list(pagelength = 25))) 
    }) 


    output$mymap <- renderLeaflet({ 
    leaflet() %>% 
     addTiles() %>% 
     addMarkers(lat = 17.95, lng = - 67.05, popup = "La Parguera ") %>% 
     addMarkers(lat = 18.00, lng = -67.50, popup = "Mona Island") %>% 
     addMarkers(lat = 18.2, lng = -69.00, popup = "Isla Catalina") 
    }) 
    observeEvent(input$laparguera, { 
    output$tbl <- DT::renderDataTable(DT::datatable(parguera, options = list(pagelength = 25))) 
    }) 
    observeEvent(input$mona, { 
    output$tbl <- DT::renderDataTable(DT::datatable(monaisland, options = list(pagelength = 25))) 
    }) 
    observeEvent(input$isla, { 
    output$tbl <- DT::renderDataTable(DT::datatable(islacatalina, options = list(pagelength = 25))) 
    }) 

    output$plot1 <- renderPlot({ 
    if(length(input$visualize) == 0) return() 
    isolate({ 
     if(length(input$checkbox) == 0) return() 
     incheckbox <- input$checkbox 
    }) # end isolate 
    if(length(incheckbox) == 1) { 
     switch(incheckbox, 
       "Mona Island"= { gplot <- ggplot(data = plotdata) + 
       geom_smooth(mapping = aes(x = Year1, y = RLIMona), fill = "navyblue", na.rm = TRUE) + 
       ylab("Candelas (5-year Running Average)") + 
       guides(fill = FALSE) 
       print(gplot) }, 
       "Isla Catalina"= { gplot6 <- ggplot(data = plotdata) + 
       geom_smooth(mapping = aes(x = Year1, y = RLICatalina), fill = "red", na.rm = TRUE) + 
       ylab("Candelas (5-year Running Average)") + 
       xlim(1837, 1992) + 
       guides(fill = FALSE) 
       print(gplot6) }, 
       "La Parguera"= { gplot7 <- ggplot(data = plotdata) + 
       geom_smooth(mapping = aes(x = Year1, y = RLILAPARGUERA2004), fill = "green", na.rm = TRUE) + 
       ylab("Candelas (5-year Running Average)") + 
       xlim(1853, 1992) 
       print(gplot7) } 
     ) # end switch 
    } else if(length(incheckbox) == 2) { 
     if(all(c("La Parguera", "Mona Island") %in% incheckbox)) { 
     gplot2 <- ggplot(data = plotdata) + 
      geom_smooth(mapping = aes(x = Year1, y = RLIMona), fill = "navyblue", na.rm = TRUE) + 
      ylab("Candelas (5-year Running Average)") + 
      xlim(1853, 1992) + 
      geom_smooth(mapping = aes(x = Year1, y = RLILAPARGUERA2004), fill = "green", na.rm = TRUE) 
     print(gplot2) 
     } else if(all(c("Mona Island", "Isla Catalina") %in% incheckbox)) { 
     gplot4 <- ggplot(data = plotdata) + 
      geom_smooth(mapping = aes(x = Year1, y = RLIMona), fill = "navyblue", na.rm = TRUE) + 
      ylab("Candelas (5-year Running Average)") + 
      geom_smooth(mapping = aes(x = Year1, y = RLICatalina), fill = "red", na.rm = TRUE) + 
      xlim(1837, 1992) 
     print(gplot4) 
     } else if(all(c("La Parguera", "Isla Catalina") %in% incheckbox)) { 
     gplot5 <- ggplot(data = plotdata) + 
      geom_smooth(mapping = aes(x = Year1, y = RLICatalina), fill = "red", na.rm = TRUE) + 
      ylab("Candelas (5-year Running Average)") + 
      geom_smooth(mapping = aes(x = Year1, y = RLILAPARGUERA2004), fill = "green", na.rm = TRUE) + 
      xlim(1853, 1992) 
     print(gplot5) 
     } 
    } else if (all(c("La Parguera", "Mona Island", "Isla Catalina") %in% incheckbox)) { 
     gplot3 <- ggplot(data = plotdata) + 
     geom_smooth(mapping = aes(x = Year1, y = RLIMona), fill = "navyblue", na.rm = TRUE) + 
     ylab("Candelas (5-year Running Average)") + 
     geom_smooth(mapping = aes(x = Year1, y = RLILAPARGUERA2004), fill = "green", na.rm = TRUE) + 
     geom_smooth(mapping = aes(x = Year1, y = RLICatalina), fill = "red", na.rm = TRUE) + 
     xlim(1853, 1992) 
     print(gplot3) 
    } 

    }) 
} 

# Run the application 
shinyApp(ui = ui, server = server) 

그리고 내 데이터 : 여기 내 코드입니다

dropbox.com/s/50emrio782fosiy/RShinyCoral.csv?dl=0 보관함에서 madhatter5의 데이터를 가져 싶은 분들을 위해

+0

, 그래서 세 번째 탭의 코드가 fluidRow'에 내장되어 (열 (12, plotOutput ("plot1")) , ... '. 그래서 tabPanel을 닫으십시오 ("데이터 테이블",'새 테이블을 열기 전에 괜찮을 것입니다.) – BigDataScientist

답변

2

는,

plotdata <- read_csv("https://www.dropbox.com/s/50emrio782fosiy/RShinyCoral.csv?dl=1") 

을 그리고 당신은 이전 탭의 괄호를 닫해야합니다 : dl=1readr::read_csv을 사용

enter image description here

봐라 : 당신이 전에 탭을 닫습니다 didnt는

enter image description here

+0

Dan 감사합니다 !!!!! – madhatter5