i'm try to plot multiple x-axis with shiny.
the problem is i can't get variable name(Cities and Month) to show under the chart. the plot i can do
I want to show variable name to under the chart. my datasheet datatable
mycode
library(shiny)
library(plotly)
data <- data.frame(Month,Cities,Accident,Robberies,Born,Dead)
ui <- fluidPage(
titlePanel("BABABA BABANANA"),
sidebarLayout(
sidebarPanel(
selectInput("var_y1",
label = "Choose a Y1-axis ",
choices = c("ACC","ROB","born","dead"),
selected = "ACC"),
br(),
actionButton("close", "Click to disconnect")
),
mainPanel(
textOutput("min_max")
)
),
hr(),
fluidRow(
column(4, verbatimTextOutput("value")),
column(4, verbatimTextOutput("range"))
)
)
server <- function(input, output) {
observeEvent(input$close, {
stopApp()
})
output$selected_var <- renderPlotly({
xaxis <- list(title = 'Cities & Month','tickvals'= seq(1, length(data$Cities)),
'ticktext' = paste(data$Month,data$Cities, sep='<br />'),
'tickmode' = 'array',autotick = F)
yaxis <- list(title = 'number of person' )
r <- plot_ly(data, x=seq(1, length(data$Cities)),y = ~Accident,name = 'Accident/Month', type = 'scatter', mode = 'lines+markers', line = list(shape = "spline"))%>%
layout(title = 'Accident of 3Cities',xaxis = xaxis,yaxis = yaxis)
s <- plot_ly(data,x=seq(1, length(data$Cities)),y = ~Robberies,name = 'Robberies/Month', type = 'scatter', mode = 'lines+markers', line = list(shape = "spline")) %>%
layout(title = 'Robberies of 3Cities',xaxis = xaxis,yaxis = yaxis)
if(input$var_y1 == "ACC"){
r
}
else if(input$var_y1 == "ROB"){
s
}
})
}
# Run the app ----cc
shinyApp(ui = ui, server = server)
I want to pass this to do the next step Many Thanks