2016-06-10 1 views
0

작업 버튼을 사용하여 이전 조건 패널을 반환하려고합니다. 지금까지 일련의 조건부 패널을 탐색하기 위해 다음 코드를 작성했지만 입력 값을 업데이트 할 수 없어 이전 사례로 돌아갈 수 없습니다.R Shiny : 이전 작업 버튼을 사용하여 이전 조건 패널로 이동

경고 : 오류

shinyUI(
    fluidPage(
    conditionalPanel(
     condition <- "typeof input.link_click === 'undefined'", 
     leafletOutput("Map", width = 1000, height = 500) 

    ), 


    conditionalPanel(
     condition <- "typeof input.link_click_Site === 'undefined' && typeof input.link_click !== 'undefined'", 


     leafletOutput("CountryMap", width = 1000, height = 500) 

    ), 
    conditionalPanel(
     condition <- "typeof input.link_click_Site !== 'undefined'", 

     h3("Plots related to site chosen"), 
     textOutput(outputId = "Check"), 
     actionButton("Back", "Back") 
    ) 
) 
) 
,369

ui.R을 : $ < -.reactivevalues에 :는 다음과 같이 읽기 전용 reactivevalues ​​개체 +

코드에 값을 할당하려고 시도

server.R

library(shiny) 
library(leaflet) 
library(maps) 

shinyServer(function(input, output, session) { 

Country = map("world", fill = TRUE, plot = FALSE, regions="USA") 
output$Map <- renderLeaflet({ 
    leaflet(Country) %>% addTiles() %>% setView(0, 0, zoom = 2)%>% 
    #leaflet(target) %>% addTiles() %>% 
    addPolygons(fillOpacity = 0.6, 
       fillColor = 'blue', 
       smoothFactor = 0.5, stroke = TRUE, weight = 1, popup = paste("<b>", "USA", "</b><br>", 
                       actionLink(inputId = "View", 
                         label = "View Details", 
                         onclick = 'Shiny.onInputChange(\"link_click\", Math.random())'))) 
}) 

output$CountryMap <- renderLeaflet({ 

    leaflet(Country) %>% addTiles() %>% 
    fitBounds(Country$range[1], Country$range[3], Country$range[2], Country$range[4])%>% 
    addMarkers(lng = -71.03 , lat = 42.37, popup = paste("<b>", "Boston", "</b><br>", 
                 actionLink(inputId = "View", 
                    label = "View Details", 
                    onclick = 'Shiny.onInputChange(\"link_click_Site\", Math.random())'))) 
}) 


observeEvent(input$link_click_Site, { 
    output$Check <- renderText("Success") 

}) 

observeEvent(input$Back, { 
    input$link_click_Site <- 0 
}) 

})

답변

1

난 당신이 제어 할 수 있습니다, 당신은 테스트 conditionalPanels 입력 값에 유형을 추가하는 것이 좋습니다.

현재 입력 link_clicklink_click_Siteundefined인지 확인하고 있습니다. 설정이 완료되면 customMessageHandler으로 재설정 할 수 있지만 물론 undefined으로 설정하면 안됩니다. JavaScript null과 같은 고유 한 값을 선택합니다.

그래서 기본적으로 모든 조건 변경은 정의되지 않은 또는 null 또는 유사 널 (null), 정의되지 아닙니다. 그런 다음 입력을 재설정하여 null으로 설정할 수 있습니다. 아래

참조 코드 :

library(shiny) 
library(leaflet)  
library(maps) 

ui <- shinyUI(
    fluidPage(
    tags$script(" 
     Shiny.addCustomMessageHandler('resetInputValue', function(variableName){ 
     Shiny.onInputChange(variableName, null); 
     }); 
    "), 

    conditionalPanel(
     condition <- "input.link_click === undefined || input.link_click === null", 
     leafletOutput("Map", width = 1000, height = 500) 

    ), 


    conditionalPanel(
     condition <- "(input.link_click_Site === undefined || input.link_click_Site === null) && (input.link_click !== undefined && input.link_click !== null)", 


     leafletOutput("CountryMap", width = 1000, height = 500) 

    ), 
    conditionalPanel(
     condition <- "(input.link_click_Site !== undefined && input.link_click_Site !== null)", 

     h3("Plots related to site chosen"), 
     textOutput(outputId = "Check"), 
     actionButton("Back", "Back") 
    ) 
) 
) 

server <- function(input, output, session) { 

    Country = map("world", fill = TRUE, plot = FALSE, regions="USA") 
    output$Map <- renderLeaflet({ 
    leaflet(Country) %>% addTiles() %>% setView(0, 0, zoom = 2)%>% 
     #leaflet(target) %>% addTiles() %>% 
     addPolygons(fillOpacity = 0.6, 
        fillColor = 'blue', 
        smoothFactor = 0.5, stroke = TRUE, weight = 1, popup = paste("<b>", "USA", "</b><br>", 
                       actionLink(inputId = "View", 
                          label = "View Details", 
                          onclick = 'Shiny.onInputChange(\"link_click\", Math.random())'))) 
    }) 

    output$CountryMap <- renderLeaflet({ 

    leaflet(Country) %>% addTiles() %>% 
     fitBounds(Country$range[1], Country$range[3], Country$range[2], Country$range[4])%>% 
     addMarkers(lng = -71.03 , lat = 42.37, popup = paste("<b>", "Boston", "</b><br>", 
                 actionLink(inputId = "View", 
                    label = "View Details", 
                    onclick = 'Shiny.onInputChange(\"link_click_Site\", Math.random())'))) 
    }) 


    observeEvent(input$link_click_Site, { 
    output$Check <- renderText("Success") 

    }) 

    observeEvent(input$Back, { 
    session$sendCustomMessage(type = 'resetInputValue', message = "link_click_Site") 
    session$sendCustomMessage(type = 'resetInputValue', message = "link_click") 
    }) 
} 

shinyApp(ui, server) 
관련 문제