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
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;
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
add a comment |
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
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 observerplotlyProxy
.
– 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
add a comment |
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
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
r
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 observerplotlyProxy
.
– 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
add a comment |
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 observerplotlyProxy
.
– 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
add a comment |
1 Answer
1
active
oldest
votes
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)
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 ofplotlyProxy()
? I wasn't able to find an example of usingplotlyProxy()
in combination with plotly events.
– Christian
Mar 28 at 13:47
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
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 ofplotlyProxy()
? I wasn't able to find an example of usingplotlyProxy()
in combination with plotly events.
– Christian
Mar 28 at 13:47
add a comment |
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)
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 ofplotlyProxy()
? I wasn't able to find an example of usingplotlyProxy()
in combination with plotly events.
– Christian
Mar 28 at 13:47
add a comment |
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)
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)
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 ofplotlyProxy()
? I wasn't able to find an example of usingplotlyProxy()
in combination with plotly events.
– Christian
Mar 28 at 13:47
add a comment |
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 ofplotlyProxy()
? I wasn't able to find an example of usingplotlyProxy()
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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