2016-09-27 80 views
-1

單擊按鈕是創建bsmodal窗口的唯一方法?如何打開bsmodal閃亮R

舉例來說,是否有可能點擊高圖表並打開bsmodal窗口?

預先感謝您

+0

總是好的你有什麼代碼實現你想要的功能 – jbkunst

回答

0

在highchars(然後highcharter),你需要使用JavaScript事件。您可以知道用戶何時點擊圖表中的某個系列。特別是你可以使用像這樣使用使用jquery通過@Skalbhile給出的答案和模態的名字:

highchart() %>% 
     hc_chart(type = "column") %>% 
     hc_add_series(data = c(1, 2, 3)) %>% 
     hc_add_series(data = c(2, 1, 3), name = "other data") %>% 
     hc_plotOptions(
     series = list(
      point = list(
      events = list(
       click = JS("function(){ 
         /* alert(this.series.name + ' ' + this.category); */ 
         /* here you activate trigger the modal */ 
         $('#modalExample').modal('show'); 
         }") 
      ) 
      ) 
     ) 
     ) 

所以最後一個演示可以是:

library(shiny) 
library(shinyBS) 
library(highcharter) 

shinyApp(
    ui = 
    fluidPage(
    highchartOutput("chart"), 
    bsModal("modalExample", "Data Table", "tabBut", size = "large", 
      "Modal Content") 
), 
server = 
function(input, output, session) { 

    output$chart <- renderHighchart({ 

    highchart() %>% 
     hc_chart(type = "column") %>% 
     hc_add_series(data = c(1, 2, 3)) %>% 
     hc_add_series(data = c(2, 1, 3), name = "other data") %>% 
     hc_plotOptions(
     series = list(
      point = list(
      events = list(
       click = JS("function(){ 
         /* alert(this.series.name + ' ' + this.category); */ 
         /* here you activate trigger the modal */ 
         $('#modalExample').modal('show'); 
         }") 
      ) 
      ) 
     ) 
     ) 
    }) 


}) 
0

你可以做到這一點編程AS-

$("#modal_id").modal('show'); 
+0

我應該在click javascript函數中使用那段代碼嗎?如果我這樣做:bsModal(「modal_id」,「Data Table」,xxxxx,size =「large」,dataTableOutput(「distTable」))),通常代表按鈕警報的「xxxxx」應該是什麼? – hsilva