Shiny / Plotly: Update plot with labels of only selected pointsLabel points in geom_pointcannot coerce type 'closure' to vector of type 'character'Shiny Plotly reactive data plotShiny Plotly event_data Error only with shiny serverRemembering Selected Points on Plot in ShinyCenter plotly plot in R shinyadding overlay of centiles to ggplot in Shiny appNo plot displayed with plotly in shinyReactive resizing of plotly graph in R ShinyShiny R Application to let users modify dataframe by lasso selection

Multi tool use
Multi tool use

What are these funnel-looking green things in my yard?

What is a good class if we remove subclasses?

Why command hierarchy, if the chain of command is standing next to each other?

Modeling the uncertainty of the input parameters

Escape Velocity - Won't the orbital path just become larger with higher initial velocity?

Graphs for which a calculus student can reasonably compute the arclength

Aderet's Anonymous Sefer and Haskamah?

Are there really no countries that protect Freedom of Speech as the United States does?

The cat ate your input again!

Why aren’t there water shutoff valves for each room?

Is it okay to write non-offensive humor into meeting minutes?

How big are the Choedan Kal?

What is the hottest thing in the universe?

Software for validating answers from students

How is являться different from есть and быть

Does EU compensation apply to flights where the departure airport closes check-in counters during protests?

What can Amex do if I cancel their card after using the sign up bonus miles?

How much can I judge a company based on a phone screening?

Does one make a shehecheyanu on "used" jewelry?

How far did Gandalf and the Balrog drop from the bridge in Moria?

Is there a SQL/English like language that lets you define formulations given some data?

Is this n-speak?

Flood on the top floor

Using hearing aids on the sabbath?



Shiny / Plotly: Update plot with labels of only selected points


Label points in geom_pointcannot coerce type 'closure' to vector of type 'character'Shiny Plotly reactive data plotShiny Plotly event_data Error only with shiny serverRemembering Selected Points on Plot in ShinyCenter plotly plot in R shinyadding overlay of centiles to ggplot in Shiny appNo plot displayed with plotly in shinyReactive resizing of plotly graph in R ShinyShiny R Application to let users modify dataframe by lasso selection






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Using R Shiny and plotly I created a interactive scatter plot.



How can I modify my code to interactively label only the points which were selected by the user?



Example plot



Thank you so much for your help!
All the best,
Christian



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)

output$plot <- renderPlotly(
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
)


shinyApp(ui, server)









share|improve this question


























  • I don't understand, your example is not reactive at all and gets never replotted? Anyway, you can update plotly objects without complete redraw using an observer plotlyProxy.

    – AEF
    Mar 27 at 13:58











  • Thank you a lot for your comment, AEF! Now I updated my question and added a plot to make it clearer.

    – Christian
    Mar 27 at 15:41

















1















Using R Shiny and plotly I created a interactive scatter plot.



How can I modify my code to interactively label only the points which were selected by the user?



Example plot



Thank you so much for your help!
All the best,
Christian



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)

output$plot <- renderPlotly(
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
)


shinyApp(ui, server)









share|improve this question


























  • I don't understand, your example is not reactive at all and gets never replotted? Anyway, you can update plotly objects without complete redraw using an observer plotlyProxy.

    – AEF
    Mar 27 at 13:58











  • Thank you a lot for your comment, AEF! Now I updated my question and added a plot to make it clearer.

    – Christian
    Mar 27 at 15:41













1












1








1








Using R Shiny and plotly I created a interactive scatter plot.



How can I modify my code to interactively label only the points which were selected by the user?



Example plot



Thank you so much for your help!
All the best,
Christian



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)

output$plot <- renderPlotly(
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
)


shinyApp(ui, server)









share|improve this question
















Using R Shiny and plotly I created a interactive scatter plot.



How can I modify my code to interactively label only the points which were selected by the user?



Example plot



Thank you so much for your help!
All the best,
Christian



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)

output$plot <- renderPlotly(
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
)


shinyApp(ui, server)






r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 15:44







Christian

















asked Mar 27 at 10:19









ChristianChristian

62 bronze badges




62 bronze badges















  • I don't understand, your example is not reactive at all and gets never replotted? Anyway, you can update plotly objects without complete redraw using an observer plotlyProxy.

    – AEF
    Mar 27 at 13:58











  • Thank you a lot for your comment, AEF! Now I updated my question and added a plot to make it clearer.

    – Christian
    Mar 27 at 15:41

















  • I don't understand, your example is not reactive at all and gets never replotted? Anyway, you can update plotly objects without complete redraw using an observer plotlyProxy.

    – AEF
    Mar 27 at 13:58











  • Thank you a lot for your comment, AEF! Now I updated my question and added a plot to make it clearer.

    – Christian
    Mar 27 at 15:41
















I don't understand, your example is not reactive at all and gets never replotted? Anyway, you can update plotly objects without complete redraw using an observer plotlyProxy.

– AEF
Mar 27 at 13:58





I don't understand, your example is not reactive at all and gets never replotted? Anyway, you can update plotly objects without complete redraw using an observer plotlyProxy.

– AEF
Mar 27 at 13:58













Thank you a lot for your comment, AEF! Now I updated my question and added a plot to make it clearer.

– Christian
Mar 27 at 15:41





Thank you a lot for your comment, AEF! Now I updated my question and added a plot to make it clearer.

– Christian
Mar 27 at 15:41












1 Answer
1






active

oldest

votes


















1














Below is a possible solution. I use a reactive function to "label" selected points. I wasn't sure how exactly you want to display the IDs for selected points. The code adds the ID as text when a point is selected. Also, I add some jitter to move the IDs away from the points.



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)
output$plot <- renderPlotly(
data <- get_data()
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point() + geom_text(data=subset(data, show_id),aes(X1,X2,label=ID), position = position_jitter(width = 20,height = 20))
ggplotly(p, source = "subset") %>% layout(dragmode = "select")
)

get_data <- reactive(
event.data <- event_data("plotly_selected", source = "subset")
data <- data %>% mutate(show_id = FALSE)
if (!is.null(event.data))
data$show_id[event.data$pointNumber + 1] <- TRUE

data
)


shinyApp(ui, server)





share|improve this answer

























  • Thank you, that works! Unfortunately, my real plots contain a few thousands of points, so I was wondering whether it's possible to avoid redrawing the plot and just do an update? Do you know how to do it; e.g. with the help of plotlyProxy()? I wasn't able to find an example of using plotlyProxy() in combination with plotly events.

    – Christian
    Mar 28 at 13:47










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374799%2fshiny-plotly-update-plot-with-labels-of-only-selected-points%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Below is a possible solution. I use a reactive function to "label" selected points. I wasn't sure how exactly you want to display the IDs for selected points. The code adds the ID as text when a point is selected. Also, I add some jitter to move the IDs away from the points.



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)
output$plot <- renderPlotly(
data <- get_data()
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point() + geom_text(data=subset(data, show_id),aes(X1,X2,label=ID), position = position_jitter(width = 20,height = 20))
ggplotly(p, source = "subset") %>% layout(dragmode = "select")
)

get_data <- reactive(
event.data <- event_data("plotly_selected", source = "subset")
data <- data %>% mutate(show_id = FALSE)
if (!is.null(event.data))
data$show_id[event.data$pointNumber + 1] <- TRUE

data
)


shinyApp(ui, server)





share|improve this answer

























  • Thank you, that works! Unfortunately, my real plots contain a few thousands of points, so I was wondering whether it's possible to avoid redrawing the plot and just do an update? Do you know how to do it; e.g. with the help of plotlyProxy()? I wasn't able to find an example of using plotlyProxy() in combination with plotly events.

    – Christian
    Mar 28 at 13:47















1














Below is a possible solution. I use a reactive function to "label" selected points. I wasn't sure how exactly you want to display the IDs for selected points. The code adds the ID as text when a point is selected. Also, I add some jitter to move the IDs away from the points.



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)
output$plot <- renderPlotly(
data <- get_data()
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point() + geom_text(data=subset(data, show_id),aes(X1,X2,label=ID), position = position_jitter(width = 20,height = 20))
ggplotly(p, source = "subset") %>% layout(dragmode = "select")
)

get_data <- reactive(
event.data <- event_data("plotly_selected", source = "subset")
data <- data %>% mutate(show_id = FALSE)
if (!is.null(event.data))
data$show_id[event.data$pointNumber + 1] <- TRUE

data
)


shinyApp(ui, server)





share|improve this answer

























  • Thank you, that works! Unfortunately, my real plots contain a few thousands of points, so I was wondering whether it's possible to avoid redrawing the plot and just do an update? Do you know how to do it; e.g. with the help of plotlyProxy()? I wasn't able to find an example of using plotlyProxy() in combination with plotly events.

    – Christian
    Mar 28 at 13:47













1












1








1







Below is a possible solution. I use a reactive function to "label" selected points. I wasn't sure how exactly you want to display the IDs for selected points. The code adds the ID as text when a point is selected. Also, I add some jitter to move the IDs away from the points.



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)
output$plot <- renderPlotly(
data <- get_data()
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point() + geom_text(data=subset(data, show_id),aes(X1,X2,label=ID), position = position_jitter(width = 20,height = 20))
ggplotly(p, source = "subset") %>% layout(dragmode = "select")
)

get_data <- reactive(
event.data <- event_data("plotly_selected", source = "subset")
data <- data %>% mutate(show_id = FALSE)
if (!is.null(event.data))
data$show_id[event.data$pointNumber + 1] <- TRUE

data
)


shinyApp(ui, server)





share|improve this answer













Below is a possible solution. I use a reactive function to "label" selected points. I wasn't sure how exactly you want to display the IDs for selected points. The code adds the ID as text when a point is selected. Also, I add some jitter to move the IDs away from the points.



library(plotly)
library(shiny)
library(dplyr)

data <- data.frame(matrix(runif(500,0,1000), ncol = 2, nrow = 100)) %>%
mutate(ID = row_number())

ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom"))

server <- function(input, output, session)
output$plot <- renderPlotly(
data <- get_data()
p <- ggplot(data, aes(x = X1, y = X2, key = ID)) +
geom_point() + geom_text(data=subset(data, show_id),aes(X1,X2,label=ID), position = position_jitter(width = 20,height = 20))
ggplotly(p, source = "subset") %>% layout(dragmode = "select")
)

get_data <- reactive(
event.data <- event_data("plotly_selected", source = "subset")
data <- data %>% mutate(show_id = FALSE)
if (!is.null(event.data))
data$show_id[event.data$pointNumber + 1] <- TRUE

data
)


shinyApp(ui, server)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 19:27









TomTom

1096 bronze badges




1096 bronze badges















  • Thank you, that works! Unfortunately, my real plots contain a few thousands of points, so I was wondering whether it's possible to avoid redrawing the plot and just do an update? Do you know how to do it; e.g. with the help of plotlyProxy()? I wasn't able to find an example of using plotlyProxy() in combination with plotly events.

    – Christian
    Mar 28 at 13:47

















  • Thank you, that works! Unfortunately, my real plots contain a few thousands of points, so I was wondering whether it's possible to avoid redrawing the plot and just do an update? Do you know how to do it; e.g. with the help of plotlyProxy()? I wasn't able to find an example of using plotlyProxy() in combination with plotly events.

    – Christian
    Mar 28 at 13:47
















Thank you, that works! Unfortunately, my real plots contain a few thousands of points, so I was wondering whether it's possible to avoid redrawing the plot and just do an update? Do you know how to do it; e.g. with the help of plotlyProxy()? I wasn't able to find an example of using plotlyProxy() in combination with plotly events.

– Christian
Mar 28 at 13:47





Thank you, that works! Unfortunately, my real plots contain a few thousands of points, so I was wondering whether it's possible to avoid redrawing the plot and just do an update? Do you know how to do it; e.g. with the help of plotlyProxy()? I wasn't able to find an example of using plotlyProxy() in combination with plotly events.

– Christian
Mar 28 at 13:47






Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374799%2fshiny-plotly-update-plot-with-labels-of-only-selected-points%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







bM,Kg3ZYUdUfXk,afhz,bJk,2,PWDJAIOgjhbRluObgRlkNGhgrCXK,GBmknN5QAZ,X,Zv,c 9MjGDYyn9M7R p,hTH8qy9RRIxt,OE
SPyWT7hjdhS3RFSEvr7jjwObhg3E7l k3xTDvR0 eYU4REP

Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현