you seem to be using a single name 'scale_input' to try to do two different things
a) as a function that can provide a y aesthetic by transforming Cases_Count
b) as an optional scale_y_continious that might be added to a sequence of ggplot calls.
I think the latter may be superflous, but we can find a solution, if you look at my reprex and find it lacking.
library(shiny)
library(tidyverse)
ui <- fluidPage(
headerPanel(title = "Shiny Tabs output Example"),
sidebarLayout(
sidebarPanel( width = 3,
selectInput("country_id", "Select your countries for cases (multiple selection allowed)",
choices = c("India","Russia","US","UK"), multiple = T,
selected = c("India","Russia","US")))
,
mainPanel( width = 9,
tabsetPanel(type = "tab",
tabPanel("Box Plot",
radioButtons("scale_input", label = "Choose y axis scale",
choices = c("Normal" = "norm",
"log" = "lnorm"), inline = T),
plotOutput("boxplot_id")
)
)
)
)
)
server <- function(input, output) {
filter_react <- reactive({
tibble(Country_Region=c("India","Russia","US","UK"),
Cases_Count = c(1,2,4,8)
,Case_Type = c(1,1,1,1)
) %>%
filter(Country_Region %in% input$country_id)
})
output$boxplot_id <- renderPlot({
scale_input_func <- function(x, y) {
func <- switch(x,
norm = identity,
lnorm = log2
)
func(y)
}
filter_react() %>%
ggplot(aes(x = Country_Region, y = scale_input_func(input$scale_input,
Cases_Count), colour = Country_Region)) + # fill = c("maroon","red","blue","orange")
# scale_y_continuous(trans = "log2") +
geom_point(alpha = 0.3, position = "jitter") +
geom_boxplot(alpha = 0, colour = "black") + #
facet_wrap(~Case_Type) +
theme_classic() +
theme(axis.text.y = element_text(size = 11)) +
labs(y="log of Cases Count", title = "Box Plot Comparison of Countries Cases according to Types" )
})
}
shinyApp(ui, server)