Hi,
Using ggplot function in a shiny output, i receive this warning only when x-axis is reduced to single factor.
" Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON. "
If x-axis is > 1 factor, works without warning.
I tried to convert my dataset(dataframe) in a named list :
Running the following example, as you can see, the second part generates Json message :
library(shiny)
library(ggplot2)
ui <- fluidPage(
tabsetPanel(
tabPanel("no message", plotOutput("quietPlot")),
tabPanel("generates `Input to asJSON` message", plotOutput("noisyPlot"))
)
)
# Define server logic required to draw cols
server <- function(input, output, session) {
output$quietPlot <- renderPlot({
ggplot(
data = data.frame(z = c("a", "b"), n = c(1, 2)),
aes(x = z, y = n)
) + geom_col()
})
output$noisyPlot <- renderPlot({
ggplot(
data = data.frame(z = c("a"), n = c(1)),
aes(x = z, y = n)
) + geom_col()
})
}
shinyApp(ui = ui, server = server)
In my case, dataset come from a reactive function, so x-axis can have 1 or multiple factors : the Json message appears in the R console when only 1 factor in the variable.
weird bug ! I did experience it in your reprex.
I found a way to make it go away.
relies on loading plotly library, changing from plotOutput to plotlyOutput, and finally from renderPlot to renderPlotly. Everything else the same the warning disappears.