You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to create a heatmap with R plotly in which the user can select a specific point ("block"). However, when the heatmap was based on a data.frame() then the clicked point information is only recorded if the first point in that row is not missing (z is not NA). For heatmaps based on a matrix() I don't experience any problem.
In the reproducible example: E.g. try to select the point with x = b and y = 1.
library(shiny)
library(plotly)
ui<- fluidPage(
fluidRow(column(6, h4("Heatmap based on data.frame()"),
plotlyOutput("plot1"),
h4("Selected point in heatmap"),
verbatimTextOutput("selected1")
),
column(6,
h4("Heatmap based on matrix()"),
plotlyOutput("plot2"),
h4("Selected point in heatmap"),
verbatimTextOutput("selected2")
)
)
)
server<-function(input, output) {
randomValues<- rnorm(9)
# Heatmap based on data.frame(): not working correctly, try to select x = b; y = 1output$plot1<- renderPlotly({
set.seed(1)
myData<-data.frame(x= rep(letters[1:3], times=3),
y= rep(as.character(1:3), each=3), value=randomValues)
myData$value[1] <-NA
plot_ly(
x=~x, y=~y, z=~value, data=myData,
type="heatmap", source="plot1"
)
})
output$selected1<- renderPrint(
event_data("plotly_click", source="plot1")
)
# Heatmap based on matrix()output$plot2<- renderPlotly({
m<-matrix(randomValues, nrow=3, ncol=3, byrow=TRUE)
m[1,1] <-NA
plot_ly(
x= c("a", "b", "c"), y= as.character(1:3),
z=m, type="heatmap", source="plot2"
)
})
output$selected2<- renderPrint(
event_data("plotly_click", source="plot2")
)
}
shinyApp(ui=ui, server=server)
The text was updated successfully, but these errors were encountered:
Thanks for the report. Looks like event_data() is generally broken when x/y/z are all vectors of the same length (notice how z isn't reported in the cells that "work"). Turns out the pointNumber emitted by plotly.js refers to a relevant cell of the heatmap (i.e., it emits the relevant row and column index), but plotly isn't currently accounting for that.
I tried to create a heatmap with R plotly in which the user can select a specific point ("block"). However, when the heatmap was based on a data.frame() then the clicked point information is only recorded if the first point in that row is not missing (z is not NA). For heatmaps based on a matrix() I don't experience any problem.
In the reproducible example: E.g. try to select the point with x = b and y = 1.
The text was updated successfully, but these errors were encountered: