【问题标题】:How to open a bsmodal shiny R如何打开一个bsmodal闪亮的R
【发布时间】:2017-02-04 19:11:04
【问题描述】:

点击按钮是创建bsmodal窗口的唯一方法吗?

是否有可能,例如,点击一个高图栏并打开一个 bsmodal 窗口?

提前谢谢你

【问题讨论】:

  • 总是好的你有什么代码来实现你想要的

标签: javascript r shiny shinybs


【解决方案1】:

在 highchars(然后是 highcharter)中,您需要使用 javascript 事件。您可以知道用户何时单击图表中的某些系列。特别是,您可以使用 @Skalbhile 使用 jquery 和模态名称给出的答案来使用类似的东西:

    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');
                         }")
              )
            )
          )
        )
    })


})

【讨论】:

    【解决方案2】:

    你可以通过编程方式来做——

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

    【讨论】:

    • 我应该在click javascript函数函数中使用那段代码吗?如果我这样做: bsModal("modal_id", "Data Table", xxxxx, size = "large", dataTableOutput("distTable")) ) ,通常代表按钮警报的“xxxxx”应该是什么?
    猜你喜欢
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 2021-04-11
    • 2019-02-23
    • 2017-05-18
    • 1970-01-01
    相关资源
    最近更新 更多