R Shiny输出基于点击交互式图
R Shiny output based on clicking on interactive plot
我正在尝试制作一个闪亮的应用程序。在一行中我有 2 列,第一列是甘特图。我想做到这一点,当你点击其中一个栏时,它会在另一栏中显示与该体验相关的文本。
这是我的甘特图的数据示例。
> 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
我已经阅读了关于此的 'similar' 帖子,但有点迷茫。
我有点卡住了,我想我需要在 plotoutput 中使用 click 并在某处使用 observeEvents。
任何帮助表示赞赏,
谢谢
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)
})
}
由于您没有提供功能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)
我正在尝试制作一个闪亮的应用程序。在一行中我有 2 列,第一列是甘特图。我想做到这一点,当你点击其中一个栏时,它会在另一栏中显示与该体验相关的文本。
这是我的甘特图的数据示例。
> 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
我已经阅读了关于此的 'similar' 帖子,但有点迷茫。 我有点卡住了,我想我需要在 plotoutput 中使用 click 并在某处使用 observeEvents。 任何帮助表示赞赏, 谢谢
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)
})
}
由于您没有提供功能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)