r - 使用反应数据集的模块内部的renderHighchart
问题描述
我正在尝试基于模块创建一个闪亮的应用程序,并且我需要在模块highchart
内部添加一个模块,当用户从selectInput
下拉列表中选择一个值时,图形会在该模块中更新。这个想法是,当用户从 UI 中的框中选择一个值时selectInput
,这会过滤数据集,然后highchart
更新。问题是我无法将过滤后的数据集传递给myModuleServer
(见下文)。我怎样才能做到这一点?
这是数据集:
df <- data.frame(label = c('A','B'), value = c(10,25))
这些是模块 UI 和服务器:
myModuleUI <- function(id) {
ns <- NS(id)
tagList(
textOutput(ns("title")),
textOutput(ns("text")),
highchartOutput(ns("graph")))}
myModuleServer <- function(input, output, session, action, dataset) {
output$title <- renderText({paste0("You selected letter: ",action())})
output$text <- renderText({paste0("In the dataset the letter selected corresponds to number: ", dataset()$value)})
output$graph <- renderHighchart({hchart(dataset(), 'bar', hcaes(x=dataset()$label, y=dataset()$value))})
}
在 Shiny App 的 UI 和服务器组件下方:
ui <- fluidPage(
fluidRow(
column(width = 3, wellPanel(selectInput('dummy', 'Select a letter', choices = c('A', 'B')))),
column(width = 6, myModuleUI("module1")))
)
server <- function(input, output, session) {
reactiveData <- reactive({input$dummy})
reactiveDataSet <- reactive({df %>% filter(label == input$dummy)})
callModule(myModuleServer, 'module1', action = reactiveData, dataset = reactiveDataSet)
}
shinyApp(ui, server)
解决方案
推荐阅读
- java - 如何使用 stashboard 创建仪表板状态应用程序?
- c# - JustMock SQL 插入检查外键
- node.js - 如何在 node-fetch 中设置内容类型
- html - 冲突的 OL 和 UL ::before 选项
- python - 如何解决我的 python 代码(数组和绘图)中的问题?
- firebase - 使用 FirebaseAuth 在我的颤振应用程序中重置密码
- sql - 在 PgAdmin 4 实用程序中找不到
- c++ - 这个类是否满足分配器的要求?
- javascript - 在 ReactJS 中获取和缓存图像
- java - 为什么我在 VS Code 中找不到 Java 类路径错误