2017-07-17 33 views
0

下面是我正在處理的內容。底部和右邊的線條圖代表主要地塊沿各自軸線的投影。 ContourShiny - > Plotly-> Contour - > event_data()

當我放大的主要情節,我想預測,以根據XMIN,XMAX,y最小和y,並進一步項目僅縮放什麼的主要情節是展示,而不是總是完全突出的主要情節。

這可能嗎?我嘗試使用event_data(「plot_hover」)和event_data(「plot_selected」),但都沒有效果。他們都提出了空。

對於更簡單的圖表有很多文檔,但對輪廓沒有太多,所以我想我會問這個。

這裏是我的代碼(老實說,很簡陋)的簡化版本:

ui.R

shinyUI(dashboardPage(
    dashboardHeader(title = "Oscillations in Spectroscopy"), 
    dashboardSidebar(sidebarMenu(
    id = "mytabs", 
    menuItem(
     "Data Input", 
     tabName = "input", 
     icon = icon("dashboard") 
    ) 
)), 
    dashboardBody(tabItems(tabItem(
    "input", 
    box(
     title = "Data Input", 
     status = "warning", 
     solidHeader = TRUE, 
     width = "100%", 
     height = "100%", 
     fluidPage(fluidRow(
     column(7, 
       plotlyOutput("raw"), 
       plotlyOutput("raw.x")), 
     column(2, width = 5, 
       plotlyOutput("raw.y")) 
    )) 
    ) 
))) 
)) 

Server.r

shinyServer(function(input, output, session) { 
    process.data <- reactive({ 
    #Do some back - end stuff 
    return(df) 
    }) 

    output$raw <- renderPlotly({ 
    print(.mainplot()) 
    }) 

    output$raw.x <- renderPlotly({ 
    .xplot() 
    }) 

    output$raw.y <- renderPlotly({ 
    .yplot() 
    }) 

    .mainplot <- function() { 
    df <- data.frame(process.data()) 
    p <- 
     plot_ly(
     df, 
     x = ~ series, 
     y = ~ time, 
     z = ~ value, 
     type = "contour", 
     source = "A" 
    ) %>% hide_colorbar() 

    return (p) 
    } 

    .xplot <- function() { 
    df <- data.frame(process.data()) 
    p <- 
     plot_ly(
     df, 
     x = ~ series, 
     y = ~ value, 
     type = 'scatter', 
     mode = 'lines' 
    ) %>% 
     layout(xaxis = list(title = ""), 
      yaxis = list(title = "", showticklabels = F)) 
    return(p) 
    } 
    .yplot <- function() { 
    df <- data.frame(process.data()) 
    p <- 
     plot_ly(
     df, 
     x = ~ x, 
     y = ~ y, 
     type = 'scatter', 
     mode = 'lines' 
    ) %>% 
     layout(xaxis = list(title = ""), 
      yaxis = list(title = "", showticklabels = F)) 
    return (p) 
    } 

}) 

回答

相關問題