2016-09-26 23 views
0

嘗試在閃亮的應用中渲染Plotly圖形。基本圖形正在生成,但無法格式化軸。能夠在Plotly Web應用程序中獲得所需的圖形選項,其佈局如下所示。如何在renderPlotly中指定詳細的佈局(Shiny r)

"layout": { 
     "autosize": true, 
     "height": 831.625, 
     "hovermode": "x", 
     "width": 1480, 
     "xaxis": { 
      "autorange": true, 
      "hoverformat": "%Y-%m", 
      "range": [ 
       1356978600000, 
       1391193000000 
      ], 
      "rangeselector": { 
       "buttons": [ 
        { 
         "label": "reset", 
         "step": "all" 
        }, 
        { 
         "label": "#1", 
         "step": "month" 
        } 
       ] 
      }, 
      "tickformat": "%Y-%m", 
      "tickmode": "auto", 
      "tickprefix": "", 
      "title": "B", 
      "type": "date" 
     }, 
     "yaxis": { 
      "autorange": true, 
      "range": [ 
       -19.888888888888893, 
       397.8888888888889 
      ], 
      "title": "A", 
      "type": "linear" 
     } 
    } 

在閃亮的代碼中指定此佈局時遇到問題。對於簡單的對象,如標題,它可以工作(如下所示)。

output$plot <- renderPlotly({ 
new_plot <- plot_ly(plot_data, x = plot_data$FY_Month, y = plot_data$Booking_Amount , name = "Test Data (Actual)") 

new_plot <- layout(new_plot,title = "Random Title") 
new_plot 
}) 

我該如何給複雜的xaxis和yaxis佈局?

回答

0

找到了自己的問題的答案。可以如下指定xaxis和yaxis佈局:

x_axis <- list(
     title = "Fiscal Year/Month", 
     autorange = "true", 
     hoverformat = "%Y-%m", 
     tickformat = "%Y-%m", 
     tickmode = "auto", 
     type = "date" 
    ) 
y_axis <- list( 
     title = "A", 
     type ="linear" 
) 


output$plot <- renderPlotly({ 
new_plot <- plot_ly(plot_data, x = plot_data$FY_Month, y = plot_data$Booking_Amount , name = "Test Data (Actual)") 

new_plot <- layout(new_plot,title = "Random Title") 
new_plot <- layout(new_plot, xaxis=x_axis, yaxis = y_axis) 
new_plot 
}) 

類似地,可以指定其他這樣的格式。使用以下參考。 Plotly R API reference doc for Axes Labels

相關問題