我有一个闪亮的应用程序,下面显示一个直方图。此直方图取决于侧边栏的numericInput()
。我的目标是将x轴标签始终设置为:5、10、15、20等。我将tick0
设置为5,将dtick
设置为5,但是当我选择显示超过5,那么我的x轴标签就像6,11,16等。不管numericInput()
值是多少,是否都可以稳定x轴值5,10,15等?
library(shiny)
library(plotly)
# Define UI for miles per gallon application
ui <- pageWithSidebar(
# Application title
headerPanel("Miles Per Gallon"),
sidebarPanel(
uiOutput("filt")
),
mainPanel(
plotlyOutput("pl")
)
)
# Define server logic required to plot various variables against mpg
server <- function(input, output) {
name<-c("rre","2df","3df","4sd","5fds","6ds4","7sf","8sdf","9sf","10fds","fg")
count<-c(2,3,4,5,6,7,5,6,1,10,11)
num<-data.frame(
name,count
)
output$filt<-renderUI({
numericInput("n1", ">", 5, min = 1, max = max(num$count), step = 1,
width = NULL)
})
x <- list(
dtick = 5,
tick0 = 5
)
d<-reactive({
num[ which(num$count > input$n1), ]
})
output$pl<-renderPlotly(
plot_ly(x = as.factor(d()[,2]), type = "histogram")%>%
# Add titles in plot and axes
layout(barmode = "overlay",xaxis=x)
)
}
shinyApp(ui, server)