我尝试将sidebarLayout
与fillPage
一起使用,以使绘图适合完整的窗口大小。以下是我的尝试,但似乎不起作用。我怎样才能纠正我的代码才能使其正常工作?
提前谢谢你。
library(plotly)
if (interactive()) {
ui <- fillPage(titlePanel("Active in last day"),
sidebarLayout(
sidebarPanel(
dateRangeInput(
"date_time_1",
"Time",
min = '2014-12-01',
max = Sys.Date() - 1,
start = Sys.Date() - 60,
end = Sys.Date() - 1
),
actionButton("btn_download", "Download"),
width = 3
),
# Show a plot of the generated distribution
mainPanel(fillRow(
plotly::plotlyOutput(
outputId = "chart",
width = "100%",
height = "100%"
),
height = "100%"
))
))
server <- function(input, output, session) {
output$chart <- renderPlotly({
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo)
plot_ly(
data,
x = ~ Animals,
y = ~ SF_Zoo,
type = 'bar',
name = 'SF Zoo'
) %>%
add_trace(y = ~ LA_Zoo, name = 'LA Zoo') %>%
layout(yaxis = list(title = 'Count'), barmode = 'group')
})
}
shinyApp(ui, server)
}
答案 0 :(得分:0)
侧栏布局导致了这个问题。我编辑了你的代码,使它占据了整个页面。
library(plotly)
if (interactive()) {
ui <- fillPage(titlePanel("Active in last day"),
#sidebarLayout(
#sidebarPanel(
dateRangeInput(
"date_time_1",
"Time",
min = '2014-12-01',
max = Sys.Date() - 1,
start = Sys.Date() - 60,
end = Sys.Date() - 1
),
actionButton("btn_download", "Download"),
width = 3
#)
,
# Show a plot of the generated distribution
#mainPanel(
fillRow(
plotly::plotlyOutput(
outputId = "chart",
width = "100%",
height = "100%"
),
height = "100%"
)#)
)#)
server <- function(input, output, session) {
output$chart <- renderPlotly({
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo)
plot_ly(
data,
x = ~ Animals,
y = ~ SF_Zoo,
type = 'bar',
name = 'SF Zoo'
) %>%
add_trace(y = ~ LA_Zoo, name = 'LA Zoo') %>%
layout(yaxis = list(title = 'Count'), barmode = 'group')
})
}
shinyApp(ui, server)
}
希望它有所帮助!