R 基于点击交互式绘图的闪亮输出

问题描述 投票:0回答:1

我正在尝试制作一个闪亮的应用程序。在一行中有两列,第一列是甘特图。 我想做到这一点,以便当您单击其中一个栏时,它会在另一列中显示与该体验相关的文本。

这是我的甘特图的数据示例。

    > experiences_head
       Type           Institution           Degree                Major start finish                                                 name
1 Education     McGill University           B. Eng    Civil Engineering  1995   1999       McGill University - B. Eng - Civil Engineering
2 Education University of Toronto            M.Eng Chemical Engineering  2000   2002 University of Toronto - M.Eng - Chemical Engineering
3 Education University of Toronto             Ph.D Chemical Engineering  2002   2008  University of Toronto - Ph.D - Chemical Engineering
4      Work Geosyntec Consultants       Consultant                       2008   2009                   Geosyntec Consultants - Consultant
5      Work                  EMBL Bioinformatician                       2009   2013                              EMBL - Bioinformatician
6      Work                  EMBL   Data Scientist                       2013   2016                                EMBL - Data Scientist
                                notes
1                   Wastwater project
2                Treatability Studies
3 Optimizing Cuture growth conditions
4                 Biomarker protocols

我已经阅读了有关此问题的“类似”帖子,但我有点迷失。 我有点卡住了,我想我需要在绘图输出中使用单击并在某处观察事件。

     source("resume_functions.R")
    ui<- 
          fluidRow(
            id = "title_bar",
            titlePanel(title = "Shiny Resume")
          ),
          fluidRow(
            # Text Section ----
            column(
              width = 8,
              
              # Description ----
              h3("Personal Summary"),
              p(Personal_summary)
            ),
          column(
            width=4,
            h3("Personality"),
            plotOutput('radar')
          )
          ),
          fluidRow(
            column(
              width=8,
              h3("Experience"),
                plotOutput("gant",click="gant_bar")
            ),
            column(
              width=4,
              h3("Competencies"),
              textOutput("exp_notes")
            )
          ),
          fluidRow(id="Skills",
                   h3("Skills"),
                   plotOutput("skills")
                   )
        
        ) # end ui
              
        server <- function(input, output) {
          
          # radar personality plo
          output$radar <- renderPlot({
            radar_plot(personality_data_w)
          })
          
          # Gant Plot ----
          output$gant <- renderPlot({
            plot_gant(experiences)
          })
          ## plot Notes based on which bar is clicked on gant
  ##
  output$exp_notes <- renderText({
    req(input$plot_click)
    browser() #interactive debugger
    near_points(experiences,input$plot_click)  # ? don't know how to specify that I want text from a specific column
  })
          # skills Plot ----
          output$skills <- renderPlot({
            skills_lolli_plot(datAnal_skills)
          })
        }

enter image description here

r shiny shiny-reactivity
1个回答
1
投票

由于您没有提供功能

plot_gant
,我创建了自己的甘特图版本来演示如何显示注释:

library(tidyverse)
library(shiny)

experiences <- tribble(
  ~name, ~start, ~finish, ~notes,
  "Civil Engineering", 1995, 1999, "Wastwater project",
  "M.Eng Chemical Engineering", 2000, 2002, "Treatability Studies",
  "Ph.D - Chemical Engineering", 2002, 2008, "Optimizing growth conditions"
)

ui <- fluidPage(
  plotOutput("gant", click = "gant_click"),
  textOutput("notes")
)

server <- function(input, output, session) {
  output$notes <- renderText({
    req(input$gant_click)

    # input is continiously scaled.
    # round to get next row id
    # y if coord_flip(), x otherwise
    row_id <- round(input$gant_click$y)

    str_glue(
      "clicked:", experiences[[row_id, "name"]],
      "notes:", experiences[[row_id, "notes"]],
      .sep = "\n"
    )
  })

  output$gant <- renderPlot({
    experiences %>%
      ggplot(aes(x = name)) +
      geom_linerange(aes(ymin = start, ymax = finish), size = 10) +
      coord_flip()
  })
}

shinyApp(ui, server)
© www.soinside.com 2019 - 2024. All rights reserved.