为什么闪亮的App使用高亮功能将伪造的窗口小部件添加到Plotly图中,并且selectize = TRUE? [英] Why does shiny App add a spurious widget to a Plotly graph using highlight function and selectize=TRUE?
问题描述
我用ggplotly制作了一个图表,以显示10位参与者在三个测试中获得的结果.该图同时显示了散点图(个人参与者)和摘要统计信息(箱线图),它们按实验分组.我添加了一个selectize设置为TRUE的突出显示功能,以便用户可以在filter_select框中搜索特定参与者,并在图形上突出显示参与者的结果.
I produced a graph with ggplotly to display the results that 10 participants achieved in three tests. The graph shows both a scatter plot (individual participants) and summary statistics (boxplot) grouped by experiment. I added a highlight function with selectize set to TRUE, so that the user can search for a particular participant in a filter_select box and highlight the participant's results on the graph.
当我运行代码时没有任何反应时,可以得到预期的结果,即上面带有filter_select框的图可以搜索参与者. 但是,当我在一个闪亮的应用程序中渲染Plotly图时,我得到了一个附加的窗口小部件,该窗口小部件似乎什么也没做,但确实使布局混乱(运行下面的Shiny App代码以查看效果).
When I run the code without shiny I get what's expected, that is the graph with a filter_select box above it to search for participants. But when I render the Plotly graph within a shiny app, I get an additional widget that doesn't seem to do anything but does really confuse the layout (run the Shiny App code below to see the effect).
library(shiny)
library(plotly)
library(shinyWidgets)
dataset <- tibble(Name=rep(LETTERS[1:10],3),Result=sample(100,30),
Experiment=c(rep("T1",10),rep("T2",10),rep("T3",10)))
ui <- fluidPage(
fluidRow(
column(width = 10, offset = 1,
plotlyOutput("graph")
)
)
)
server <- function(input, output, session) {
output$graph <- renderPlotly({
d <- highlight_key(dataset,~Name,group="Select participant")
p <- ggplot(d,aes(Experiment,Result,fill=Experiment,text=paste0("<b>Name: ",
Name,"</b><br />Result: ",Result,"%"))) +
geom_boxplot()+
geom_point(size=2,position=position_jitterdodge(dodge.width = 0.4)#,
)+ggtitle("Results by Experiment (all subjects)")+
theme(legend.position="none",axis.text.x=element_text(size=15),
axis.title.x=element_text(color="red",size=15))
p <- ggplotly(p,tooltip=c("text"))
p <- style(p,hoverlabel=list(bgcolor="white",bordercolor="black",font="Arial"))
highlight(p,on="plotly_click",off="plotly_doubleclick",selectize=TRUE,color="green")
})
}
shinyApp(ui, server)
我想把这个虚假的部件从plotlyOutput中删除;我浏览了许多有关闪闪发光的突出问题的问题和答案,但是没有一个问题与我遇到的问题类似.我想知道是否有人解决了这个问题并找到了解决方案.非常感谢您的帮助.
I'd like to get this spurious widget removed from the plotlyOutput; I have looked through numerous questions and answers on the shiny-plotly-highlight topic but none had anything similar to the problem I am having. I wonder whether anyone out there has come up against this issue and found a solution. I'd really appreciate any help with this.
推荐答案
@StéphaneLaurent@IqbalAdijali非常感谢!你是最棒的!我一直在寻找解决方案.此刻之后,您启发了我学习Java脚本.
@StéphaneLaurent @IqbalAdijali Thanks so much! You are the best! I was looking all over for a solution for this. You have inspired me to learn java script after this moment.
我将为其他想要实现上述JS代码的人添加-我将其完全粘贴到tabPanel中的UI中,就像这样(不要忘记更改绘图名称!"graph"或"plot_15" ;在这种情况下,为您的地块名称):
I will add for others wanting to implement the JS code above - I pasted it into the UI in a tabPanel exactly like this (do not forget to change the plot name! "graph", or "plot_15" in this case, to your plots name):
tags$head(tags$script(HTML(
'
$(document).on("shiny:value", function(e){
if(e.name === "plot_15"){
setTimeout(function(){
$("#plot_15").prev().children()[1].style.display = "none";
}, 0);
}
});
'
))
此外,您可能需要添加逗号或括号以分别分隔表达式或close语句.
Also, you may need to add a comma or parenthesis to separate expressions or close statements respectively.
这篇关于为什么闪亮的App使用高亮功能将伪造的窗口小部件添加到Plotly图中,并且selectize = TRUE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!