I want to use different drop-down bottoms in the shiny-dashboard to filter the data set, which is read by the first drop-down field. The first drop-down bottom loops over all file names in the data-folder, loads and plots the data (it works well). In the next step, I want to apply ratings as a filter, which is chosen by another drop-down bottom. However, I get the following error,
if(dataRating =
^
Warning: Error in sourceUTF8: Error sourcing C:\Temp\RtmpScI3tC\fileb32838a12cde
Stack trace (innermost first):
1: runApp
Error in sourceUTF8(serverR, envir = new.env(parent = globalenv())) :
Error sourcing C:\Temp\RtmpScI3tC\fileb32838a12cde
My Gui:
library("shiny")
# Define UI for dataset viewer app ----
ui <- fluidPage(
# App title ----
titlePanel("Default"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Selector for choosing dataset ----
selectInput(inputId = 'date',
label = 'Choose a date:',
choices = list.files(path = "C:/R_myfirstT/data",
full.names = FALSE,
recursive = FALSE)),
# Input: Selector for choosing dataset ----
selectInput(inputId = 'rating',
label = 'Choose the rating:',
choices = c("All",0,1,2,3))
),
# Main panel for displaying outputs ----
mainPanel(
plotOutput("plot")
)
)
)
and the Server:
# Define server ----
server <- function(input, output) {
# Rating
dataRating <- reactive({
rating <- input$rating
if (is.null(infile)){
return(NULL)
}
})
#
dataset <- reactive({
infile <- input$date
if (is.null(infile)){
return(NULL)
}
read.csv(paste0('C:/R_myfirstT/data',infile),header=TRUE, sep=";")
})
### OutPut
if(dataRating ="All"){
output$plot <- renderPlot({
x <- dataset()$Marktwert
hist(x, breaks = 40)
})
}
}
The dashboard without if
statement in Server.R
looks like
I would like to know,
specialy:
what did I do wrong in this case?
generally:
how can I apply different inputs from different drop-down bottoms with data.table operation as filters?
Addendum:
I changed the if
-statement to if(dataRating() =="All")
and
dataRating <- reactive({
rating <- input$rating
to
dataRating <- reactive({
dataRating <- input$rating
I found a suggestion here. However, I get another error
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.)
Sample data looks like:
stand Rating LGD Marktwert EL absolut
6010 3 3 1142345261 1428757
6010 3 3 849738658 1028973
6010 1 3 1680222820 220554
6010 1 3 896459567 116673
6010 0 3 1126673222 72077
6010 1 3 704226037 93310
- 1 4 336164879 49299
6010 0 3 948607746 60443
6070 1 3 265014117 34170
6020 3 3 47661945 58551
6050 2 3 307011781 115959
6020 0 1 1064022992 20320
6010 0 3 831782040 52950
6080 3 3 19367641 20286
- 2 4 197857365 87608
6010 1 3 679828856 90884
6050 3 3 317092037 372362
6080 3 3 20223616 21929
6010 1 3 693736624 96899
6050 3 3 308447822 372915
6010 4 3 177281455 862068