I've seen some cool uses of shiny with R to make web applications and wanted to try to learn how to use it myself. I am doing the tutorial right now, but when I get to the Inputs and Outputs part of the tutorial (http://rstudio.github.io/shiny/tutorial/#inputs-and-outputs) I run in to a problem.
Specifically, I am getting an error that says:
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive function.)
I've tried a bunch of different things and searched everywhere online but can't figure out what the problem is. I am running R version 2.15.2 on OS X Version 10.8.3. My default browser is Chrome.
Thanks for the help.
Along with Shiny elements, you can use HTML elements to stylize your content in your application. In my opinion, R Shiny is very easy to learn despite how powerful the tool is. If you're working on a side project or looking to add something to your portfolio, I highly recommend trying it out.
But the simplest way to run a Shiny app is to run it locally. You only need the shiny R package installed, and you can run the app in your browser.
Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.
I know this question is a bit dated, but responding for those who might come searching when faced with the same error message.
Since you haven't included your code, let's look at why this error message happens in general.
When the error message says "Operation not allowed without an active reactive context." what it is saying is that you are accessing a "reactive" element inside the ShinyServer
function, but outside any of the reactive functions such as renderTable
or renderPlot()
etc.
shinyServer(function(input, output) {
abc <- input$some.input.option
#other reactives here
})
reactive
This will work:
shinyServer(function(input, output) {
abc <- reactive({
abc <- input$some.input.option
})
#other reactives here
})
And now, from inside the ShinyServer function, you can access that Input parameter by calling abc()
Note the parenthesis since it is a reactive function.
Hope that helps.
For me, I had this issue when I forgot about using renderPrint
, which is easy to forget when you're just starting up.
For example:
shinyServer(function(input,output) {
output$outputString <- input$something
}
)
When what I really needed to do was
shinyServer(function(input,output) {
output$outputString <- renderPrint({input$something})
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With