2017-12-20 11 views
0

私の光沢のあるアプリには、mainPanelに3つのtabPanelがあり、各tabPanelにはそれぞれ独自のsidebarPanelがあります。私はsidebarPanel設定するshinyBSを使用する「のショーをして隠す」光沢のあるサイドバーパネルを非表示にする

observeEvent(input$showpanel, { 
    if(input$showpanel == TRUE) { 
     removeCssClass("Main", "col-sm-12") 
     addCssClass("Main", "col-sm-8") 
     shinyjs::show(id = "Sidebar") 
     shinyjs::enable(id = "Sidebar") 
    } 
    else { 
     removeCssClass("Main", "col-sm-8") 
     addCssClass("Main", "col-sm-12") 
     shinyjs::hide(id = "Sidebar") 
    } 
    }) 

サーバー

bsButton("showpanel", "Show/Hide sidebar",icon = icon("toggle-off"), type = "toggle",style = "info", value = TRUE) 

を私は期待のように数回は、2つのタブが動作テストが、プロットとタブ(私はplotly使用)、サイドバーを隠しているように見えますが、他のタブをクリックしてPlotタブに戻るまで、プロットは自動的に伸びません。ですから、フルスクリーンでプロットを見たい場合は、別のタブをクリックして余分にして戻ってくる必要があります。

この問題を解決するにはどうすればよいですか?

おかげ

答えて

1

次の時間reproducible exampleを投稿してください...これを行うには

library(shiny) 
library(shinydashboard) 
library(plotly) 
library(shinyjs) 
library(shinyBS) 

ui <- dashboardPage(
    dashboardHeader(), 
    dashboardSidebar(), 
    dashboardBody(
    useShinyjs(), 
    extendShinyjs(text = 'shinyjs.hideSidebar = function(params) { $("body").addClass("sidebar-collapse"); 
       $(window).trigger("resize"); }'), 
    extendShinyjs(text='shinyjs.showSidebar = function(params) { $("body").removeClass("sidebar-collapse"); 
        $(window).trigger("resize"); }'), 
    bsButton("showpanel", "Show/Hide sidebar",icon = icon("toggle-off"), type = "toggle",style = "info", value = TRUE), 
    fluidRow(tabsetPanel(id='tabs', 
         tabPanel(value=1,title="Tab1"), 
         tabPanel(value=2,title="Tab2"), 
         tabPanel(value=3, title="Plot", 
            fluidRow(
            column(12, 
              plotlyOutput('plot', height=800)))) 
    ) 
    ))) 


server <- function(input, output, session) { 


    output$plot <- renderPlotly({ 
    plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length) 
    }) 

    observe({ 
    if(input$showpanel == TRUE) { 
     js$showSidebar() 
    } 
    else { 
     js$hideSidebar() 
    } 
    }) 
} 

shinyApp(ui, server) 

一つの方法は、あなたが追加したときにプロットを強制的にサイドバーを削除/イベントのサイズを変更するウィンドウをトリガすることですサイドバーが表示/非表示にされた後、正しいサイズで再描画されます。この目的のために、私は使用しました:

useShinyjs(), 
    extendShinyjs(text = 'shinyjs.hideSidebar = function(params) { $("body").addClass("sidebar-collapse"); 
       $(window).trigger("resize"); }'), 
    extendShinyjs(text='shinyjs.showSidebar = function(params) { $("body").removeClass("sidebar-collapse"); 
        $(window).trigger("resize"); }') 

機能。

関連する問題