【发布时间】:2020-06-30 11:05:32
【问题描述】:
在尝试帮助 this person 时,我遇到了 shinyjs 的问题。当我单击下面代码中的矩形时,我想显示一个绘图。
在下面的示例中,单击绿色大矩形会打印文本,应该是这样的:
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)
但是,如果我尝试用绘图替换打印,我将面临错误:
警告:origRenderFunc 中的错误:缺少参数“名称”,没有默认值
这是产生错误的代码:
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)
我认为问题来自函数onclick,因为如果我将renderPlot 放在onclick 之外,我将无法重现此错误。有人知道怎么解决吗?
【问题讨论】: