Reputation: 2384
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 (or put this into server.r)
library(shinydashboard)
library(plotly)
server.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 version 3.2.3
shiny version 13.0
shinydashbaord 0.5.1
plotly 2.0.16
empty environment
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.
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?
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;
whereas the visible ones have
width: 100%; height: 400px; visibility: inherit;
so I imagine this is related (though causation direction is unknown...)
Upvotes: 2
Views: 5077
Reputation: 2384
renderPlotly({
return(plot_ly(x))
})
is broken.
renderPlotly(plot_ly(x))
works.
To do more work before rendering the plotly, do something like
renderPlotly(yourFunctThatGeneratesAPlotly(input$Whatever))
Upvotes: 1