我在网上到处查了一下没有结果。我似乎无法让这些图在最大化盒子时将其高度和宽度最大化到整个窗口大小。这是我使用的要求bs4Dash。我查看了这篇文章,但提供的解决方案似乎对我不起作用。我缺少什么?
library(shiny)
library(bs4Dash)
library(circlepackeR) # devtools::install_github("jeromefroe/circlepackeR")
library(wordcloud2) # devtools::install_github("lchiffon/wordcloud2")
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(id="histbox",
title = "hist box",
plotOutput("plot1",
height = 250),
maximizable = T),
box(id = "circlebox", title="circle box",
circlepackeR::circlepackeROutput("circles"), maximizable = T)
),
fluidRow(
box(id="wordlcoudbox",
title = "wordcloud box",
wordcloud2::wordcloud2Output("cloud"),
maximizable = T),
box(id = "plotlybox",
title = "plotly box",
plotly::plotlyOutput("plotlyplot"),
maximizable = T))
)
) …Run Code Online (Sandbox Code Playgroud) 我有data.frame以下内容:
dp <- structure(list(`Demand Per Section` = c(125, 350, 100, 538, 75,
25, 138, 138, 75, 150, 37, 225, 35, 40, 125, 25, 25, 125, 50,
250, 88, 325, 4, 50, 6, 5, 500, 500, 3, 146, 5, 34, 15, 51, 2,
32, 48, 18, 5, 6, 44, 16, 46, 12, 100, 750, 15, 500, 30, 333),
`Element Name` = c("Nitric acid (concentrated)", "Sulphuric acid(concentrated)",
"2-hydroxybenzoic acid", "Acetic anhydride", "2-Naphthol",
"Sodium Hydroxide", "Phenyl hydrazine hydrochloride", "Glucose",
"Sodium acetate", …Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制带有填充和 NA 值的线图。Plotly 自动用 NA 值填充我希望其为空的部分。获得正确图表的最佳方法是什么?
不能将 NA 值设置为 0。我也在使用胡佛,并且不希望将鼠标悬停在线上时得到 0 的结果。
R 数据+代码示例:
library(plotly)
set.seed(1)
A = data.frame(x = 1900:2000, value=cumsum(rnorm(101)))
A[40:70, 2:3] = NA
fig <- plot_ly(x = A$x, y = A$value, type = 'scatter', mode = 'lines', fill = 'tozeroy')
fig
Run Code Online (Sandbox Code Playgroud)
我有几个组,每个组有几个类,我测量了连续值:
set.seed(1)
df <- data.frame(value = c(rnorm(100,1,1), rnorm(100,2,1), rnorm(100,3,1),
rnorm(100,3,1), rnorm(100,1,1), rnorm(100,2,1),
rnorm(100,2,1), rnorm(100,3,1), rnorm(100,1,1)),
class = c(rep("c1",100), rep("c2",100), rep("c3",100),
rep("c2",100), rep("c4",100), rep("c1",100),
rep("c4",100), rep("c3",100), rep("c2",100)),
group = c(rep("g1",300), rep("g2",300), rep("g3",300)))
df$class <- factor(df$class, levels =c("c1","c2","c3","c4"))
df$group <- factor(df$group, levels =c("g1","g2","g3"))
Run Code Online (Sandbox Code Playgroud)
并非数据中的每个组都具有相同的类,或者换句话说,每个组都具有所有类的子集。
我试图R plotly为每个组生成密度曲线,按类别进行颜色编码,然后使用plotlyssubplot函数将它们全部组合成一个图。
这就是我正在做的:
library(dplyr)
library(ggplot2)
library(plotly)
set.seed(1)
df <- data.frame(value = c(rnorm(100,1,1), rnorm(100,2,1), rnorm(100,3,1),
rnorm(100,3,1), rnorm(100,1,1), rnorm(100,2,1),
rnorm(100,2,1), rnorm(100,3,1), rnorm(100,1,1)),
class = c(rep("c1",100), rep("c2",100), rep("c3",100),
rep("c2",100), rep("c4",100), rep("c1",100),
rep("c4",100), rep("c3",100), rep("c2",100)),
group …Run Code Online (Sandbox Code Playgroud) 假设您有一个简单的shinydashboard包含使用创建的链接menuItem和使用创建的页面tabItems:
library(shiny)
library(shinydashboard)
skin <- Sys.getenv("DASHBOARD_SKIN")
skin <- tolower(skin)
skin <- "blue"
## ui.R ##
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets",
badgeLabel = "new", badgeColor = "green")
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
h2("Dashboard tab content")
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
# Put them together into a dashboardPage
ui<-dashboardPage(
dashboardHeader(title = "Simple tabs"),
sidebar, …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试设置一个动态创建 valueBoxes 的 UI。
我选择了此处显示的代码,它完全符合我的要求,但使用了绘图。
library(shiny)
library(shinydashboard)
ui <- pageWithSidebar(
headerPanel("Dynamic number of valueBoxes"),
sidebarPanel(
selectInput(inputId = "choosevar",
label = "Choose Cut Variable:",
choices = c("Nr. of Gears"="gear", "Nr. of Carburators"="carb"))
),
mainPanel(
# This is the dynamic UI for the plots
uiOutput("plots")
)
)
server <- function(input, output) {
#dynamically create the right number of htmlOutput
# renderUI
output$plots <- renderUI({
plot_output_list <- lapply(unique(mtcars[,input$choosevar]), function(i) {
plotname <- paste0("plot", i)
# valueBoxOutput(plotname)
htmlOutput(plotname)
})
tagList(plot_output_list)
}) …Run Code Online (Sandbox Code Playgroud) 也许有些人可以告诉我为什么我为"dataVars"分配的名字在我的data.table中添加一列后没有改变(没有重新分配它们)?如何保持赋值只存储前两个列名?
谢谢!
编辑:在我看来,这不是这个问题的重复,因为我特别要求一个包含data.table列名的向量,而不是data.table本身.当然机制是相同的,但似乎指出这个机制有什么扩展效果似乎对这个网站上的其他用户有用 - 因此我不会删除这个问题.
library(data.table)
DT <- data.table(a=1:10, b=1:10)
idVars <- names(DT)
print(idVars)
# [1] "a" "b"
DT[, "c" := 1:10]
print(idVars)
# [1] "a" "b" "c"
# devtools::session_info()
# data.table * 1.11.6 2018-09-19 CRAN (R 3.5.1)
Run Code Online (Sandbox Code Playgroud) 我正在绘制散点图,ggplot()如下所示:
library(data.table)
library(plotly)
library(ggplot2)
library(lubridate)
dt.allData <- data.table(date = seq(as.Date('2020-01-01'), by = '1 day', length.out = 365),
DE = rnorm(365, 4, 1), Austria = rnorm(365, 10, 2),
Czechia = rnorm(365, 1, 2), check.names = FALSE)
## Calculate Pearson correlation coefficient: ##
corrCoeff <- cor(dt.allData$Austria, dt.allData$DE, method = "pearson", use = "complete.obs")
corrCoeff <- round(corrCoeff, digits = 2)
## Linear regression function extraction by creating linear model: ##
regLine <- lm(DE ~ Austria, data = dt.allData)
## Extract k …Run Code Online (Sandbox Code Playgroud) 这可能是一个相当直接的问题。
我想测试一个对象是否是一个情节对象。理想情况下,我会测试一个ggplotly()对象。
有没有简单的方法可以做到这一点?我似乎找不到这样的功能;
> x <- ggplot()
>
> is.ggplot(x)
[1] TRUE
Run Code Online (Sandbox Code Playgroud)
如果有人能指出我正确的方向,将不胜感激!
我正在使用 R 编程语言。我正在尝试学习如何在图表上叠加点,然后将它们可视化。
使用以下代码,我可以生成一些时间序列数据,按月聚合它们,取平均值/最小值/最大值,并绘制以下图表:
library(xts)
library(ggplot2)
library(dplyr)
library(plotly)
library(lubridate)
set.seed(123)
#time series 1
date_decision_made = seq(as.Date("2014/1/1"), as.Date("2016/1/1"),by="day")
property_damages_in_dollars <- rnorm(731,100,10)
final_data <- data.frame(date_decision_made, property_damages_in_dollars)
#####aggregate
final_data$year_month <- format(as.Date(final_data$date_decision_made), "%Y-%m")
final_data$year_month <- as.factor(final_data$year_month)
f = final_data %>% group_by (year_month) %>% summarise(max_value = max(property_damages_in_dollars), mean_value = mean(property_damages_in_dollars), min_value = min(property_damages_in_dollars))
####plot####
fig <- plot_ly(f, x = ~year_month, y = ~max_value, type = 'scatter', mode = 'lines',
line = list(color = 'transparent'),
showlegend = FALSE, name = 'max_value')
fig <- fig %>% add_trace(y …Run Code Online (Sandbox Code Playgroud) 我需要一条穿过该图原点的对角线
类似于 ggplot2 的东西geom_abline(intercept = 0 , slope = 1)
,但是对于 R 中的plotly
library(plotly)
fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
fig
Run Code Online (Sandbox Code Playgroud) 有没有办法在不将文件上传到 R Shiny 的情况下“查看”文件大小?
r ×12
r-plotly ×7
plotly ×6
shiny ×5
abline ×1
adminlte ×1
bs4dash ×1
data.table ×1
dplyr ×1
ggplot2 ×1
ggplotly ×1
http ×1
javascript ×1
legend ×1
markdown ×1
na ×1
plot ×1
shiny-server ×1
subplot ×1
time-series ×1
wordcloud2 ×1