I am trying to render a .Rmd file from a shiny app. I am using the shiny app so filter the data set the way I want and then use the filtered data to create a report using rmarkdown.
This is what I have tried:
# load packages
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(rmarkdown)
library(readxl)
library(dplyr)
library(tidyr)
library(stringr)
library(DT)
# data processing
source("data cleaning.R", echo = FALSE)
# Define UI
ui <- dashboardPage(
dashboardHeader(title = "Student Wellbeing Dashboard",
titleWidth = 400),
dashboardSidebar(width = 400,
sidebarMenu(
checkboxGroupButtons(inputId = "select_sections",
label = "Select Sections", choices = unique(dictionary$Dependent),
individual = TRUE,
checkIcon = list(yes = tags$i(class = "fa fa-circle",
style = "color: steelblue"),
no = tags$i(class = "fa fa-circle-o",
style = "color: steelblue")))
)
),
dashboardBody(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "style.css")
),
fluidRow(
dataTableOutput("data_out")
)
)
)
# Define server logic
server <- function(input, output) {
filtered_data <- reactive(
merged %>%
select(-Question.Id, -Answer.Id) %>%
filter(Dependent %in% input$select_sections)
)
output$data_out <- renderDataTable(filtered_data())
epp_data <- filtered_data()
rmarkdown::render("markdown.Rmd", output_file = "html_document",
params = list(data = epp_data)
)
}
# Run the application
shinyApp(ui = ui, server = server)
The source file data cleaning.R
reads to datasets and merges them together named merged
.
This is the error I am getting:
Warning: 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 expression or observer.)
54: stop
53: .getReactiveEnvironment()$currentContext
52: getCurrentContext
51: .dependents$register
50: filtered_data
49: server [E:/Projects and porfolio/Projects/fiverr/project6-update student health/health-report/abawbawbr.R#55]
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 expression or observer.)