2016-04-08 88 views
2

我在儀表板上工作,我想創建一個動態彈出框,即我們可以移動。 我可以創建一個彈出窗口,但這個是靜態的,我喜歡一個可以把它並將其移動到右側,左側...RShiny動態彈出菜單(可移動)

我彈出的一個例子:

library(shiny) 
library(shinyBS) 

shinyApp(

    ui = 
    fluidPage(
     sidebarLayout(
     box(actionButton("tabBut", "View Table")), 
     mainPanel(
      bsModal("modalExample", "Data Table", "tabBut", size = "large", 
        dataTableOutput("distTable"))))), 

    server = 
    function(input, output, session) { 
     output$distTable <- renderDataTable({ 
     x <- faithful[, 2] 
     bins <- seq(min(x), max(x), length.out = 30 + 1) 
     tab <- hist(x, breaks = bins, plot = FALSE) 
     tab$breaks <- sapply(seq(length(tab$breaks) - 1), function(i) { 
      paste0(signif(tab$breaks[i], 3), "-", signif(tab$breaks[i+1], 3))}) 
     tab <- as.data.frame(do.call(cbind, tab)) 
     colnames(tab) <- c("Bins", "Counts", "Density") 
     return(tab[, 1:3])}, 
     options = list(pageLength=10))} 
) 

result

我希望用戶可以移動此窗口。 如果您有想要更改的選項,或者如果您知道BS以外的任何其他方法閃亮創建新窗口...

先謝謝您,並且對我的英語感到抱歉!

+0

退房[superzip示例](http://shiny.rstudio.com/gallery/superzip-example.html)來查看他們如何使用'absolutePa nel',它允許你添加'draggable = T'。應該以最小的努力給你想要的東西。 – brittenb

+0

真的非常感謝你的絕對panel也可以。 – CClaire

回答

0

你可以嘗試manyally做到這一點:

1)添加腳本

2)添加可拖動

3)編輯CSS

,如:

ui = 
    fluidPage(
     tags$head(HTML('<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
        <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>')), 
     tags$script(HTML(' $(window).load(function(){ 
         $("#modalExample").draggable({ 
         handle: ".modal-header" 
            }); 
            });')), 
      tags$style(HTML(" 
      .modal-backdrop.in { 
       opacity: 0; 
      }  
       ")), 
     sidebarLayout(
     box(actionButton("tabBut", "View Table")), 
     mainPanel(

      bsModal("modalExample", "Data Table", "tabBut", size = "large", 
        dataTableOutput("distTable"))))) 
+0

是的,謝謝,它工作正常! – CClaire