我制作了一个带有ggplotly的图表,以显示10位参与者在三个测试中获得的结果。该图同时显示了散点图(单个参与者)和按实验分组的摘要统计信息(箱线图)。我添加了一个selectize设置为TRUE的突出显示功能,以便用户可以在filter_select框中搜索特定参与者,并在图形上突出显示参与者的结果。
[当我运行代码时没有任何反应时,我得到了预期的结果,即上面带有filter_select框的图形以搜索参与者。但是,当我在一个闪亮的应用程序中渲染该Plotly图时,我得到了一个附加的小部件,该部件似乎没有任何作用,但确实使布局混乱(运行下面的Shiny App代码以查看效果)。
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中删除这个虚假的小部件;我浏览了许多有关闪闪发光的突出问题的问题和答案,但是没有一个问题与我遇到的问题类似。我想知道是否有人解决了这个问题并找到了解决方案。非常感谢您的帮助。
看起来像个虫子。您可以像这样隐藏此小部件:
ui <- fluidPage(
fluidRow(
column(width = 10, offset = 1,
plotlyOutput("graph")
)
),
tags$script(
"setTimeout(function(){$('#graph').prev().children()[1].style.display = 'none';}, 500);"
)
)
这是一个更好的解决方案:
js <- '
$(document).on("shiny:value", function(e){
if(e.name === "graph"){
setTimeout(function(){
$("#graph").prev().children()[1].style.display = "none";
}, 0);
}
});
'
ui <- fluidPage(
tags$head(
tags$script(HTML(js))
),
fluidRow(
column(width = 10, offset = 1,
plotlyOutput("graph")
)
)
)