I've built a Shiny dashboard app that shows a number of metrics data of scientific articles by university School. The app is at https://ttso.shinyapps.io/2amconf and the code https://gist.github.com/tts/900b4e27bf37e8969ebd with some sample data of file dataforcharts.csv which is the data source of my question here.
My problem is the NVD3 chart on the landing tab.
At first it draws OK the selected max 2 items (=articles) from the chosen School, which is All at the beginning. But whenever I select some School - and selectizeInput then updates the list of items of that School - nothing happens.
I've tried to debug what's going on.
validate(
need(!is.null(itemsData()), "Please select some items")
)
dataC <- itemsData()
browser()
When the execution stops there, I can see that dataC do contains the chosen data.
Console utput of options(shiny.trace=TRUE) is talkative but I cannot really understand what it tries to tell me. Here's a snippet from the last message when the chart ought to render with new data, but does not.
SEND {"errors":[],"values":{"chart":"<style>.rChart {width: 800px;
height: 400px} </style>\n<script type='text/javascript'>\n
$(document).ready(function(){\n drawchart()\n });\n
function drawchart(){ \n var opts = {\n \"dom\":
\"chart\",\n\"width\": 800,\n\"height\": 400,\n\"x\":
\"id\",\n\"y\": \"value\",\n\"group\": \"variable\",\n\"type\":
\"multiBarChart\",\n\"id\": \"chart\" \n},\n data =
[ TEXT CUT OFF ] drawchart(){ \n n return chart;\n
});\n };\n</script>"},"inputMessages":[]}
Again, data= includes the correct, chosen data.
Is something wrong with my reactive values?
EDIT after observation: if I delete all selected item(s) before switching to another School, this works.
So, after some trial & error, this looks promising:
itemsData <- reactive({
if( is.null(input$items) ){
return(NULL)
}
isolate(selectedSchoolData()[selectedSchoolData()$Title %in%
input$items, ])
})
but I haven't yet got my head over isolate() so if someone could explain, why this works, I'd be grateful.