在Shiny中考虑一个完整的应用程序。有多个navbars,tabsets和plot。闪亮输出的串行触发
我需要构建的是一个单独的底部信息窗格,其中包含与每个渲染图相关的一些信息。此信息取决于绘制的图表中的实际数据。
所以这里是我想要做的 第1步:用户输入一个输入。 第二步:更新相关情节 第三步:计算在一个全局变量需要底部窗格和存储) 第四步相关的数据:一旦第三步完成后,我希望它触发底部窗格
我试过的更新使底部窗格和绘图对用户输入产生反应。 但这可能无法保证绘图渲染有机会更新信息窗格的数据。
任何提示将不胜感激。
谢谢
最小的例子是这里。注 - 我知道我可以使群集成为被动的“对象”。但交易是myPlotInfo对象在各种函数中更新得更深。因此它不容易在外面计算。
Server.R
source(util.R)
library(shiny)
myPlotInfo<-iris #setting inital value
shinyServer(function(input, output, session) {
output$plot1 <- renderPlot({
plotFunction(iris,input$xcol, input$ycol,input$clusters)
})
output$myTable<-renderDataTable({
myPlotInfo
})
})
ui.R
shinyUI(pageWithSidebar(
headerPanel('Iris k-means clustering'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable', names(iris),
selected=names(iris)[[2]]),
numericInput('clusters', 'Cluster count', 3,
min = 1, max = 9)
),
mainPanel(
plotOutput('plot1'),
dataTableOutput("myTable")
)
))
util.R
plotFunction<-function(dat,x,y,n){
par(mar = c(5.1, 4.1, 0, 1))
selectedData<-dat[, c(x, y)]
clusters <- kmeans(selectedData,n)
myPlotInfo<<-selectedData
plot(selectedData,
col = clusters$cluster,
pch = 20, cex = 3)
points(clusters$centers, pch = 4, cex = 4, lwd = 4)
}
请提供一个最小的可重复的例子 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –
你寻找“集群”约你的kmeans还是只用于计算的表格? –
其实我的目标是希望能够更新一个全局变量myPlotInfo。在剧情功能里面。而这需要依次触发输出的重新输出:输出$ myTable – guna