r - DataTable卡在R中的“处理”中
问题描述
我正在尝试将接收到的 MQTT 数据显示为 a 中的表ShinyApp
,但该表卡在“正在处理..”中。以下是我的可重现代码。我尝试了其他解决方案,但似乎没有一个适合我的要求。
library(shiny)
library(mqtt)
library(hrbrthemes)
library(tidyverse)
ui <- shinyServer(fluidPage(
fluidRow(plotOutput('plot'),
fluidRow(dataTableOutput("telemetry"))
)
))
server <- function(input, output) {
get_temps <- function(n) {
i <- 0
max_recs <- n
readings <- vector("character", max_recs)
temp_cb <- function(id, topic, payload, qos, retain) {
i <<- i + 1
readings[i] <<- readBin(payload, "character")
return(if (i==max_recs) "quit" else "go")
}
mqtt::topic_subscribe(topic = "/outbox/crouton-demo/temperature",
message_callback = temp_cb)
purrr::map(readings, jsonlite::fromJSON) %>%
purrr::map(unlist) %>%
purrr::map_df(as.list)
}
values <- reactiveValues(x = NULL, y = NULL)
observeEvent(invalidateLater(450), {
new_response <- get_temps(1)
if (length(new_response) != 0) {
values$x <- c(values$x, new_response$update.labels)
values$y <- c(values$y, new_response$update.series)
}
}, ignoreNULL = FALSE)
output$plot <- renderPlot({
xdf <- data.frame(xval = values$x, yval = values$y)
ggplot(xdf, aes(x = xval, y=yval)) +
geom_line() +
geom_point() +
theme_ipsum_rc(grid="XY")
})
show_df <- reactive({
xdf1 <- data.frame(xval = values$x, yval = values$y)
return(xdf1)
})
output$telemetry <- renderDataTable({show_df()})
}
shinyApp(ui = ui, server = server)
plot
似乎工作正常,但无法显示数据表。试过library(DT)
但没有运气。
解决方案
推荐阅读
- r - R脚本RDCOMClient无法打开xlsx文件
- r - 如何在ggplot2中指向一个历史?
- ios - 核心运动更新
- android - Android切换到多种布局
- vuejs3 - Vue 反应性:使用提供和注入创建反应性数据
- c++ - curl.lib 缺失(Visual Studio 2019,C++)
- php - 从注册到 Woocommerce Checkout 获取自定义字段
- python - Pandas:如何根据频率有效过滤数据
- mysql - 显示创建用户'root'@'localhost';给我错误 1064 (42000):您的 SQL 语法有错误;
- java - 为什么套接字 connect() 方法超时?netcat (nc) 工作正常