首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shiny -> Plotly-> Contour -> event_data()

Shiny -> Plotly-> Contour -> event_data()
EN

Stack Overflow用户
提问于 2017-07-18 06:00:53
回答 1查看 239关注 0票数 0

下面是我正在做的事情。底线图和右线图表示主图沿各自轴的投影。Contour

当我放大主图时,我希望投影根据xmin、xmax、ymin和ymax进行缩放,并进一步投影仅显示主图的内容,而不是始终完全投影主图。

这个是可能的吗?我尝试使用event_data("plot_hover")和event_data("plot_selected"),但似乎都不起作用。他们都想出了null。

有很多关于简单图形的文档,但没有那么多关于等高线的文档,所以我想我应该问一下这个。

以下是我的代码的简化版本(老实说,非常粗糙):

ui.R

代码语言:javascript
复制
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

代码语言:javascript
复制
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)
  }

})
EN

回答 1

Stack Overflow用户

发布于 2017-07-19 06:48:56

已解决:

代码语言:javascript
复制
p <-
      plot_ly(x = df[,2], y = df[,4]) %>%
        add_contour(x = dat@wavelength, y = dat@data$x, z = dat@data$spc, visible = TRUE) %>%
        add_markers(x = df[,2], y = df[,4], opacity = 0.01, hoverinfo="x+y") %>%
        layout(dragmode = "select")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45154340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档