Consider a complete app in Shiny. With multiple navbars, tabsets and plots.
What I need to build is a SEPARATE bottom info pane containing some information relevant to each of the rendered plots. This info depends on the actual data in the plotted chart.
So here is what I want to do Step1: user enters an input. Step2: Update the relevant plot Step3: compute relevant data needed for bottom pane and store in a global variable) Step4: once step3 IS COMPLETE, I want it to trigger an update of the bottom Pane
I tried to make the bottom pane AND the plot reactive to user input. BUT this may not guarantee that the plot rendering got a chance to update the data for info pane.
Any tips would be greatly appreciated.
thanks
Minimal EXAMPLE is here. NOTE - I know that I could make clusters a reactive "object". But the deal is that the myPlotInfo object is updated deep inside various functions. Hence it is not easily calculatable outside.
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)
}