While trying to help this person, I got stuck with a problem with shinyjs
.
In the example below, clicking on the big green rectangle prints the text, as it should be:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
div(id = "01",
style = "cursor:pointer; height: 300px; width: 300px; text-align: center; background-color: green",
HTML("01")),
textOutput("plot")
)
server <- function(input, output) {
onclick(id = "01", {
output$plot <- renderPrint({
print("foo")
})
})
}
shinyApp(ui, server)
However, if I try to replace the print with a plot, I am facing the error:
Warning: Error in origRenderFunc: argument "name" missing, with no default
Here's the code that creates the error:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
div(id = "01",
style = "cursor:pointer; height: 300px; width: 300px; text-align: center; background-color: green",
HTML("01")),
plotOutput("plot")
)
server <- function(input, output) {
onclick(id = "01", {
output$plot <- renderPlot({
plot(mtcars)
})
})
}
shinyApp(ui, server)
I suppose the problem comes from the function onclick
since I can't reproduce this error if I put renderPlot
outside of onclick
. Does anybody know how to solve this?
Also asked on StackOverflow