问题描述
我正在使用 Shiny,但无法显示绘图图.之前出现过,不知道怎么改的.
I'm using shiny and I can't get a plotly graph to appear. It was appearing before, I don't know what changed.
MRE:
global.r(或将其放入 server.r)
global.r (or put this into server.r)
library(shinydashboard)
library(plotly)
服务器.r
shinyServer(function(input, output, session) {
output$plotlyGraph <- renderPlotly({
input$regraph
print("graphing...")
return(plot_ly(list(blank = 0)))
})
})
ui.r
dashboardPage(
dashboardHeader(title = "The Title"),
dashboardSidebar(
actionButton("regraph", "graph again")
),
dashboardBody(
box(plotlyOutput("plotlyGraph"))
)
)
R 版本 3.2.3
闪亮版 13.0
shinydashbaord 0.5.1
shinydashbaord 0.5.1
情节 2.0.16
空旷的环境
我注意到当我运行上面的代码时,我得到一个错误 gregexpr(calltext, singleline, fixed = TRUE) 中的错误:正则表达式是无效的 UTF-8.
I noticed that when I run the above code, I get an error Error in gregexpr(calltext, singleline, fixed = TRUE) : regular expression is invalid UTF-8.
在使用 debug(gregexpr)
进行进一步调查后,我看到了这一点
Upon further investigation with debug(gregexpr)
, I see this
Called from: inherits(x, "ggplot")
debugging in: gregexpr(calltext, singleline, fixed = TRUE)
debug: {
if (!is.character(text))
text <- as.character(text)
.Internal(gregexpr(as.character(pattern), text, ignore.case,
perl, fixed, useBytes))
}
Browse[2]> text
[1] "function (x) inherits(x, "ggplot")"
不知道该怎么做.真的有一些底层代码应该修改一个字符串,然后再评估为一个函数吗?
not sure what to make of that. Is there really some under-the-hood code that's supposed to be modifying a string that is later evaluated to a function?
我找到了另一个程序,其中的 plotly 图形渲染得很好.gregrexpr() 永远不会被调用.查看生成的 HTML,有问题的有这个样式
I found another program I have where the plotly graph renders fine. gregrexpr() is never called. Looking at the generated HTML, the problematic one has this under style
width: 100%; height: 400px; visibility: hidden;
而可见的有
width: 100%; height: 400px; visibility: inherit;
所以我想这是相关的(尽管因果关系方向未知......)
so I imagine this is related (though causation direction is unknown...)
推荐答案
renderPlotly({
return(plot_ly(x))
})
坏了.
renderPlotly(plot_ly(x))
有效.
要在绘制情节之前做更多工作,请执行以下操作
To do more work before rendering the plotly, do something like
renderPlotly(yourFunctThatGeneratesAPlotly(input$Whatever))
这篇关于情节图不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!