I am trying to create a shiny dashboard to summarize customer feedback, but get error as below
Warning: Error in inherits: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
56: <Anonymous>
Error in inherits(x, "Source") :
Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
Below is the coding part, I have used.
library(shiny)
#Define UI
shinyUI(fluidPage(
#Title Panel
titlePanel(title=h4("Initial Feedback Survey",align="center")),
sidebarLayout(
#Sidebar panel
sidebarPanel(
selectInput("var","Select the variable",choices=names(data),selected=names(data)[11]),
br(),
radioButtons("color","Select the color",choices=c("Green","Red","Yellow"),selected="Green")
),
#Main Panel
mainPanel(
tabsetPanel(type="tab",
tabPanel("Data",tableOutput("data")),
tabPanel("Summary",tableOutput("counts")),
tabPanel("Plot",plotOutput("bar")))
)
)
)
)
library(shiny)
library(shinydashboard)
library(dplyr)
library(ggplot2)
library(tm)
data=read.csv("C:\\Users\\Kafeel Basha\\Desktop\\R Files\\RShiny\\Jigsaw Data Science with R.csv",header=TRUE,stringsAsFactors = FALSE,na.strings=c(" "," ","NA",NULL,""))
data=na.omit(data)
names(data) <- gsub("[..]", " ", names(data))
names(data) <- gsub("[.]", " ", names(data))
shinyServer(function(input,output){
demo=Corpus(VectorSource(input$var))
demo=tm_map(demo,content_transformer(tolower))
demo=tm_map(demo,removePunctuation)
df<- data.frame(text=unlist(sapply(demo,`[`)),stringsAsFactors=F)
df$text=ifelse(df$text=="poor"|df$text=="fair","BAD","GOOD")
df%>%group_by(text)%>%summarise(count=n(),percentage=count/nrow(df))%>%as.data.frame()->stats
rownames(stats)<-stats$text
output$data<-renderTable({head(data)})
output$counts<-renderTable({table(stats$text)})
output$bar <- renderPlot({
ggplot(stats,aes(x=stats$text,y=stats$percentage,fill=text))+geom_bar(stat="identity")+geom_text(label=stats$percentage,vjust=-0.5)+ggtitle("Bar Chart of Proportion")
})})