2014-09-18 15 views
5

Tôi đã tạo mẫu sau cho ứng dụng sáng bóng của mình.Chọn sáng bóng chuyển đến tabPanel khác bằng nút hành động hoặc một cái gì đó

 ##ui.R 
     shinyUI(navbarPage("My Application", 
     tabPanel 
     (
     "Select Data range", 
     sidebarLayout 
     (
      sidebarPanel 
      (
       h3("Select Data Range"), 
       selectInput("select", label = h3("Select Sector"),choices = list("Sector 1" = 1, "Sector 2" = 2,"Sector 3" = 3), selected = 1),br(), 
       dateRangeInput("dates", label = h3("Select Date range")),br(), 
       submitButton("Submit"),br(), 
       actionButton("action", label = "Proceed to select resolution") 
      ), 
      mainPanel("Output") 
     ) 
    ), 

     tabPanel 
     (
     "Select Resolution", 
     sidebarLayout 
     (
      sidebarPanel 
      (
       h3("Select Resolution"), 
       numericInput("num", label = h3("Select X-Grid Size"), value = 2),br(), 
       numericInput("num", label = h3("Select Y-Grid Size"), value = 2),br(), 
       numericInput("num", label = h3("Outlier Removal"), value = 2),br(), 
       numericInput("num", label = h3("Frequency"), value = 2),br(), 
       submitButton("Submit"),br(), 
       #actionButton("action", label = "Proceed to Service Parameters") 
      ), 
      mainPanel("Output") 
     ) 
    ) 

    )) 

Và các tập tin máy chủ được giữ trống cho bây giờ:

 ##server.R 
     shinyServer(function(input, output) { 
     }) 

Vấn đề là lý tưởng tôi muốn sử dụng một đầu vào như nút hành động trên TabPanel đầu tiên để điều hướng đến bảng điều khiển tab thứ hai. Bất kỳ đề xuất nào về giải pháp thay thế cũng sẽ được đánh giá cao như nhau.

Trả lời

8

Bạn có thể gửi một thông báo tùy chỉnh:

ui.R

shinyUI(navbarPage("My Application", 

       tabPanel 
       (
       "Select Data range", 
       sidebarLayout 
       (
        sidebarPanel 
        (tags$head(tags$script(' 
            Shiny.addCustomMessageHandler("myCallbackHandler", 
             function(typeMessage) {console.log(typeMessage) 
              if(typeMessage == 1){ 
              console.log("got here"); 
              $("a:contains(Select Resolution)").click(); 
              } 
              if(typeMessage == 2){ 
              $("a:contains(Select Data range)").click(); 
              } 
              }); 
              ')), 
        h3("Select Data Range"), 
        selectInput("select", label = h3("Select Sector"),choices = list("Sector 1" = 1, "Sector 2" = 2,"Sector 3" = 3), selected = 1),br(), 
        dateRangeInput("dates", label = h3("Select Date range")),br(), 
        actionButton("action", label = "Proceed to select resolution") 
        ), 
        mainPanel("Output") 
       ) 
       ), 

       tabPanel 
       (
       "Select Resolution", 
       sidebarLayout 
       (
        sidebarPanel 
        (
        h3("Select Resolution"), 
        numericInput("num1", label = h3("Select X-Grid Size"), value = 2),br(), 
        numericInput("num2", label = h3("Select Y-Grid Size"), value = 2),br(), 
        numericInput("num3", label = h3("Outlier Removal"), value = 2),br(), 
        numericInput("num4", label = h3("Frequency"), value = 2),br(), 
        actionButton("action1", label = "Proceed to Service Parameters") 

        ), 
        mainPanel("Output"), 

       ) 
       ) 

)) 

server.R

library(shiny) 
shinyServer(function(input, output,session) { 
    observe({ 
    if(input$action > 0){ 
     print('1') 
     session$sendCustomMessage("myCallbackHandler", "1") 
    } 
    }) 
    observe({ 
    if(input$action1 > 0){ 
     print('2') 
     session$sendCustomMessage("myCallbackHandler", "2") 
    } 
    }) 
} 
) 

Ngoài ra, bạn không thể có các đối tượng với id giống nhau. Lưu ý tất cả các số numericInputactionButton của bạn có cùng id. Ngoài ra tôi gỡ bỏ các nút gửi không chắc chắn bạn muốn nhiều hơn sau đó một trong những.

+0

Cảm ơn, Đó chính xác là những gì tôi cần. Các đối tượng được với cùng một id vì đây chỉ là bố trí cơ bản của ứng dụng và tôi sẽ đổi tên chúng như tôi sử dụng chúng trong server.R. – anonR

Các vấn đề liên quan