Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

Multiple x-axis didn't show variable name

$
0
0

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


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>