Insert a graph(plotly) into a R shiny

ggplot2
shiny
rstudio
plotly

#1

Hello everyone,

I have tried to create an app with R shiny in where the user can download a excel file and print an interactive graph, using plotly, with the selection of the x and y parameters from selectInput() function. When I run my app, I have this follwing warning message: Warning in origRenderFunc() :Ignoring explicitly provided widget ID "dc7a4f37ac44"; Shiny doesn't use them

My code seems code. Can you help me to see where I made a mistake and what I should modify, please?

`
library(shiny)
library(rsconnect)
library(ggplot2)
library(plotly)

plotType <- function(data, x, y, type){
switch(type,
"Line" = ggplot(data, aes_string(x, y)) + geom_line(),
"Scatterplot" = ggplot(data, aes_string(x, y)) + geom_point()
)
}

ui <- fluidPage(

sidebarPanel(
# Input: select a file
fileInput(inputId = "file1", label = "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values, text/plain",
".csv")
),
# Horizontal line
tags$hr(),
# Input: Checkbox if file has header
checkboxInput("header", "Header", TRUE),
# Input: Select separator
radioButtons(inputId ="sep", label = "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),

radioButtons(inputId = "quote", label = "Quote",
             choices = c(None = "",
                         "Double Quote" = '"',
                         "Single Quote" = "'"),
             selected = '"'),
# Horizontal line
tags$hr(),

selectInput('xcol', 'X Variable', ""),
selectInput('ycol', 'Y Variable', "", selected = ""),
 # Horizontal line
tags$hr(),
# Input: Select the type of graph 
radioButtons(inputId ="graph", label = "Type of graph:",
             choices = c("Line", 
                         "Scatterplot"),
             selected = "Line")

),

mainPanel(
tabsetPanel( type = "tabs",
tabPanel(
# App title
titlePanel("Uploading Files"),
# Output: Data file
tableOutput("contents")

             ),
             tabPanel(
               titlePanel("Plot"),
               plotOutput('MyPlot')
             ),
             tabPanel(
               titlePanel("Summary Statistics"),
               verbatimTextOutput("summary")
             )
)

)
)

server <- function(input, output, session) {

data <- reactive({
req(input$file1)

df <- read.csv(input$file1$datapath,
               header = input$header,
               sep = input$sep,
               quote = input$quote)

updateSelectInput(session, inputId = 'xcol', label = 'X Variable',
                  choices = names(df), selected = names(df)[sapply(df, is.numeric)])
updateSelectInput(session, inputId = 'ycol', label = 'Y Variable',
                  choices = names(df), selected = names(df)[sapply(df, is.numeric)])

return(df)

})

x_axe <- reactive({
data()[ , input$xcol]
})

y_axe <- reactive({
data()[, input$ycol]
})

style <- reactive({
input$graph
})

output$contents <- renderTable({
data()
})

output$MyPlot <- renderPlotly({
#x <- data()[, c(input$xcol, input$ycol)]
p <- plotType(data(), x_axe(),
y_axe(),
style())
p

})

Generate a summary table of the data uploaded

output$summary <- renderPrint({
y <- data()
summary(y)

})

}

Create Shiny app

shinyApp(ui = ui, server = server)
`
Thank you in advance for yout help!