Shinyモジュールを使用するためにシャイニーの古いアプリを移植したいと思っています。 documentationによると親のShinyサーバで反応的なデータセットを呼び出すシャイニーモジュール
:
目標は、彼らの 含むアプリケーションとの相互作用からモジュールを防ぐためではなく、これらの相互作用を明示的にするためにではありません。 モジュールが反応式を使用する必要がある場合は、反応式 式を関数パラメータとして使用します。
私は渡したいAPIなどからデータをインポートする既存の反応式を持っていますが、構文を見つけることはできません。下に与えられたShiny module exampleを修正すると、同じ問題が発生する可能性があります。
car_data()
反応性の高いデータをモジュールに渡すことができるように、以下を変更できますか?私はisolate
とcar_data/car_data()
のすべての組み合わせを試しました。私は考えることができ、困惑しています:)
私は、私の場合のようにデータを一般化しようとする必要はありません多数のデータセットに適用可能なETL関数。
library(shiny)
library(ggplot2)
linkedScatterUI <- function(id) {
ns <- NS(id)
fluidRow(
column(6, plotOutput(ns("plot1"), brush = ns("brush"))),
column(6, plotOutput(ns("plot2"), brush = ns("brush")))
)
}
linkedScatter <- function(input, output, session, data, left, right) {
# Yields the data frame with an additional column "selected_"
# that indicates whether that observation is brushed
dataWithSelection <- reactive({
brushedPoints(data(), input$brush, allRows = TRUE)
})
output$plot1 <- renderPlot({
scatterPlot(dataWithSelection(), left())
})
output$plot2 <- renderPlot({
scatterPlot(dataWithSelection(), right())
})
return(dataWithSelection)
}
scatterPlot <- function(data, cols) {
ggplot(data, aes_string(x = cols[1], y = cols[2])) +
geom_point(aes(color = selected_)) +
scale_color_manual(values = c("black", "#66D65C"), guide = FALSE)
}
ui <- fixedPage(
h2("Module example"),
linkedScatterUI("scatters"),
textOutput("summary")
)
server <- function(input, output, session) {
### My modification
### making the reactive outside of module call
car_data <- reactive({
mpg
})
## This doesn't work
## What is the syntax for being able to call car_data()?
df <- callModule(linkedScatter, "scatters", car_data(),
left = reactive(c("cty", "hwy")),
right = reactive(c("drv", "hwy"))
)
output$summary <- renderText({
sprintf("%d observation(s) selected", nrow(dplyr::filter(df(), selected_)))
})
}
shinyApp(ui, server)
これは役立つ可能性があります:http://stackoverflow.com/a/36517069/4222792なぜ外部から反応的な呼び出しを行う必要がありますか?あなたのモジュールのいくつかは出力できませんか?あなたのdataImportApiは1つのモジュールですか? –
ありがとうミカエル。その理由は、そのパッケージとして使用するための一般的なモジュールのためのものであり、私はそれに反応的なデータフレームを渡したいと思います。 – MarkeD