r - Shiny.setInputValue 不是函数错误
问题描述
我很困惑为什么以下代码会产生“Shiny.setInputValue 不是函数”错误:
library(shiny)
library(htmltools)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Test"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
),
# Show a plot of the generated distribution
mainPanel(
shiny::tags$script(htmltools::HTML('
quantityaa = 1;
console.log(quantityaa);
Shiny.setInputValue("hi", quantityaa);
'))
,
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
hi <- reactive({ input$hi})
print(hi)
}
# Run the application
shinyApp(ui = ui, server = server)
产生此错误的代码有什么问题?我看不出有什么问题,但我一定是错过了什么。
解决方案
那是因为 Shiny 还没有准备好。使用shiny:connected
事件:
$(document).on("shiny:connected", function() {
// your awesome JavaScript here can use Shiny.setInputValue
});
推荐阅读
- jenkins-pipeline - 需要通过 git sha 来结帐到 Jenkins 多分支管道
- installation - 如何在 Ubuntu 16.04 上安装 Plesk
- c# - 从通用数据类型填充 SelectListItem
- c# - 等待回调方法
- swift - 类型 'NSArray?.Type' 不符合协议 'Sequence'
- python - 如何在 Keras 中包含 tf.py_func 代码?
- qt - QHttpMultiPart 上传文件边界问题
- erlang - 如何在 Erlang/Elixir 中获取完全合格的域名(或只是域名)?
- mysql - PASSWORD() 类似 MySQL 8.0 的功能,可插入身份验证
- c# - 获取分区计数的非昂贵、有效的方法