Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中使用SweetAlert2_R_Datatables_Shiny_Sweetalert_Sweetalert2 - Fatal编程技术网

在R中使用SweetAlert2

在R中使用SweetAlert2,r,datatables,shiny,sweetalert,sweetalert2,R,Datatables,Shiny,Sweetalert,Sweetalert2,我正在尝试使用SweetAlert2弹出窗口,而不是传统的JS弹出窗口。期待一个例子,以实现相同的,因为我是新的JS概念。拜访- 在实际场景中,我希望在双击数据表行时使用这些SweetAlert2代替JS警报 带JS弹出窗口的代码: library(shiny) library(shinydashboard) library(DT) ui <- shinyUI( dashboardPage ( dashboardHeader(title="Report"), dashb

我正在尝试使用SweetAlert2弹出窗口,而不是传统的JS弹出窗口。期待一个例子,以实现相同的,因为我是新的JS概念。拜访- 在实际场景中,我希望在双击数据表行时使用这些SweetAlert2代替JS警报

带JS弹出窗口的代码:

library(shiny)
library(shinydashboard)
library(DT)

ui <- shinyUI(

dashboardPage (
    dashboardHeader(title="Report"),
    dashboardSidebar(sidebarMenu(menuItem("Table",tabName="Table"))),
    dashboardBody(      
        tabItems(
        tabItem(tabName = "Table",
            DT::dataTableOutput("DataTable")    
        )
   ))

))

server <- shinyServer(function(input, output) {
     output$DataTable <- DT::renderDataTable({
          datatable(iris,rownames=FALSE,selection = 'single',
                    options = list(
                              searching = FALSE,ordering=FALSE,
                              dom = 'Bfrtip',
                              buttons = c('copy','excel', 'pdf', 'print', 'colvis'),
                              columnDefs = list(list(visible=FALSE, targets=c(2))
          ),
     rowCallback = JS(
          "function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
          "var full_text = aData[2]",
          # Tooltip for the rows
          "$('td:eq(1)', nRow).attr('title', full_text);",
          # Showing a hand as a cursor
          "$('td:eq(1)', nRow).css('cursor','pointer');",
          "$('td:eq(1)', nRow).css('font-weight','bold');",
          "}")
      ),
      #On double Click show Alert Message
     callback = JS('
          table.on("dblclick.dt","tr", function() {
          var data=table.row(this).data();
          alert("You clicked on "+data[4]+"\'s row");})
          '))
})
})

shinyApp(ui,server)
库(闪亮)
图书馆(shinydashboard)
图书馆(DT)

ui我不熟悉这个JS库,无论如何,我认为这应该是可行的

用户界面 首先,您必须将js脚本添加到页面中(注意路径,它应该是
CDN
/www/
文件夹中的文件:

tags$head(HTML("<script type='text/javascript' src='path/to/sweetAlert2.js'></script>"))

希望这有帮助

谢谢Gamba。它很有效!与JS脚本一起,添加了SweetAlert的CSS脚本,使其具有相同的外观。CSS部分-标记$head(标记$link(rel=“stylesheet”,type=“text/CSS”,href=“SweetAlert.CSS”))
callback = JS('
    table.on("dblclick.dt","tr", function() {
        var data=table.row(this).data();
        swal({
            title: "Click!",
            text: "You clicked on "+data[4]+"\'s row",
            type: "success",
            confirmButtonText: "Cool"
        })
    )')