Reputation: 433
I am integrating a plotly graph in Shiny dashboard. However, the size and scale of the graph would change to after maximizing screen or drag the UI to a screen with different resolution.
Blow is the screenshot of the graph I want:
Blow is the screenshot of the graph after maximizing the screen:
Below is my code:
header <- dashboardHeader(
)
sidebar <- dashboardSidebar(
)
body <- dashboardBody(
box(title = "Test",
plotlyOutput("plot")
)
)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$plot <- renderPlotly({
plot_ly(x = b1image$CNT, y = b1image$Label, type = 'bar', orientation = 'h',
marker = list(color = viridis::viridis_pal(option = "C", direction =1)(max(b1image$Label) - min(b1image$Label) + 3)))
})
}
shinyApp(ui, server)
The data I used to plot is from the dataframe named b1image.
Thanks in advance.
Upvotes: 2
Views: 2525
Reputation: 4480
Maybe this can help you:
header <- dashboardHeader(
)
sidebar <- dashboardSidebar(
)
body <- dashboardBody(
box(title = "Test", width = 10, height = "500px",
plotlyOutput("plot",width = "400px", height = "400px")
)
)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$plot <- renderPlotly({
server <- function(input, output) {
output$plot <- renderPlotly({
p <- plot_ly()
p <- add_trace(p, x=a, y=b, z=c, mode="markers", type="scatter3d", marker = list(size = 5, color = 'rgba(0, 0, 0, 1)'))
p <- layout(p, scene = list(xaxis = list(title = "A",range = c(-2,2)), yaxis = list(title = "B",range = c(-2,2)), zaxis = list(title = "C",range = c(-2,2))))
p
})
}
shinyApp(ui, server)
})
}
shinyApp(ui, server)
box(title = "Test", width = 10, height = "500px",
plotlyOutput("plot",width = "400px", height = "400px")
)
Define your ploty width and height
p <- layout(p, scene = list(xaxis = list(title = "A",range = c(-2,2)), yaxis = list(title = "B",range = c(-2,2)), zaxis = list(title = "C",range = c(-2,2))))
Define your plotly range of axis
Upvotes: 2