我想将R代码转换为闪亮的仪表板

时间:2019-05-07 14:02:05

标签: r shiny plotly shinydashboard

我在R Studio中使用package plotly编写了代码,但是现在我想在一个闪亮的仪表板中实现它。不确定如何转换为ui.r和server.r。

此外,想将此图添加为selectInput框。就像在下拉菜单中单击值时一样,如果单击此图ID,则应显示该图。请帮助我。

 df <- WP1GanttData     
# Convert to dates
df$Start <- as.Date(df$Start, format = "%m/%d/%Y")  
# Choose colors based on number of resources
cols <- RColorBrewer::brewer.pal(length(unique(df$Resource)), name = "Set3")
df$color <- factor(df$Resource, labels = cols)
# Initialize empty plot
p <- plot_ly()    
for(i in 1:(nrow(df) - 1)){
  p <- add_trace(p,
                 x = c(df$Start[i], df$Start[i] + df$Duration[i]),  # x0, x1
                 y = c(i, i),  # y0, y1
                 mode = "lines",
                 line = list(color = df$color[i], width = 20),
                 showlegend = F,
                 hoverinfo = "text",                     
                 # Create custom hover text                     
                 text = paste("Task: ", df$Task[i], "<br>",
                              "Duration: ", df$Duration[i], "days<br>",
                              "Resource: ", df$Resource[i]),

                 evaluate = T  # needed to avoid lazy loading
  )
}     
p <- layout(p,                                    
            xaxis = list(showgrid = TRUE, tickfont = list(color = "#e6e6e6")),               
            yaxis = list(showgrid = TRUE, tickfont = list(color = "#e6e6e6"),
                         tickmode = "array", tickvals = 1:nrow(df), ticktext = unique(df$Task),
                         domain = c(0, 0.9)),
           # Annotations                
            annotations = list(               
              list(xref = "paper", yref = "paper",
                   x = 0.80, y = 0.1,
                   text = paste0("Total Duration: ", sum(df$Duration), " days<br>",
                                 "Total Resources: ", length(unique(df$Resource)), "<br>"),
                   font = list(color = "#ffff66", size = 12),
                   ax = 0, ay = 0,
                   align = "left"),

              # Add client name and title on top                  
              list(xref = "paper", yref = "paper",
                   x = 0.1, y = 1, xanchor = "left",
                   text = paste0("Gantt Chart: ", client),
                   font = list(color = "#f2f2f2", size = 20, family = "Times New Roman"),
                   ax = 0, ay = 0,
                   align = "left")
            ),                
           plot_bgcolor = "#343",  # Chart area color
            paper_bgcolor = "#343")  # Axis area color

1 个答案:

答案 0 :(得分:0)

在闪亮的信息中心中完成实施。

相关问题