我想使用粘贴功能将文本加粗。我如何在 R 中编写这个代码?感谢您查看这个。
observeEvent(input$submit3,{
if (input$submit3==0) return()
tagList(
lapply(1:input$numoftrends, function(j) {
trend.period <- input[[paste0("trendDateRange", j)]]
trend1 <- substr(trend.period[1],1,7)
trend2 <- substr(trend.period[2],1,7)
output[[paste0('Text', j)]] <- renderText({
#paste(" ") ## add space in between text
paste('Trend Date Range', j, ': ', trend1 ,' - ', trend2)
})
})
)
})
Run Code Online (Sandbox Code Playgroud) 我在如何在 ggplotly 中定位主标题和图例时遇到问题。我希望我的主标题位于图表顶部并左对齐。我还希望我的图例位于图表的底部中心
这是我的代码
library(ggplot2)
library(dplyr)
library(tidyr)
library(plotly)
Month_Names <- c("2010-11","2010-12",
"2011-01","2011-02","2011-03","2011-04","2011-05","2011-06","2011-07","2011-08","2011-09","2011-10","2011-11","2011-12",
"2012-01","2012-02","2012-03","2012-04","2012-05","2012-06","2012-07","2012-08","2012-09","2012-10","2012-11","2012-12",
"2013-01","2013-02","2013-03","2013-04","2013-05","2013-06","2013-07","2013-08","2013-09","2013-10","2013-11","2013-12",
"2014-01","2014-02","2014-03","2014-04","2014-05","2014-06","2014-07","2014-08","2014-09","2014-10","2014-11","2014-12",
"2015-01","2015-02","2015-03","2015-04","2015-05","2015-06","2015-07","2015-08","2015-09","2015-10","2015-11","2015-12",
"2016-01","2016-02","2016-03","2016-04","2016-05","2016-06","2016-07","2016-08","2016-09","2016-10","2016-11","2016-12",
"2017-01")
Actual_volume <- c(54447,57156,
52033,49547,58718,53109,56488,60095,54683,60863,56692,55283,55504,56633,
53267,52587,54680,55569,60013,56985,59709,61281,54188,59832,56489,55819,
59295,52692,56663,59698,61232,57694,63111,60473,58984,64050,54957,63238,
59460,54430,58901,61088,60496,62984,66895,62720,65591,67815,58289,72002,
61054,60329,69283,68002,63196,72267,71058,69539,71379,70925,68704,76956,
65863,70494,77348,70214,74770,77480,69721,83034,76761,77927,79768,81836,
75381)
df_data <- data.frame(Month_Names, Actual_volume)
trendDateRange1 <- c("2010-11-01", "2017-01-31")
trendDateRange2 <- c("2012-01-01", "2012-12-31")
trendDateRange3 <- c("2013-01-01", "2013-12-31")
numoftrends <- 3
trends <- data_frame(Start = c("2010-11", "2012-01", "2013-01"),
End = c("2017-01", "2012-12", "2013-12"))
combined_data <- df_data %>%
crossing(trends) %>%
mutate(Month_Names = as.character(Month_Names),
TrendName = paste(Start, End, sep = "-")) %>%
filter(Month_Names >= Start,
Month_Names …Run Code Online (Sandbox Code Playgroud) 我有一个使用plotly和ggplot2的代码。当我将信息悬停时,里面的信息就会重复,这表示所有图形都显示2条相同的TrendName Info行。例如,这就是悬停信息中显示的内容
月名称:2011-05实际卷:56488趋势名称:2010-11-2017-01趋势名称:2010-11-2017-01
如何仅显示1个TrendName?谢谢
这是我的代码
library(ggplot2)
library(dplyr)
library(tidyr)
library(plotly)
Month_Names <- c("2010-11","2010-12",
"2011-01","2011-02","2011-03","2011-04","2011-05","2011-06","2011-07","2011-08","2011-09","2011-10","2011-11","2011-12",
"2012-01","2012-02","2012-03","2012-04","2012-05","2012-06","2012-07","2012-08","2012-09","2012-10","2012-11","2012-12",
"2013-01","2013-02","2013-03","2013-04","2013-05","2013-06","2013-07","2013-08","2013-09","2013-10","2013-11","2013-12",
"2014-01","2014-02","2014-03","2014-04","2014-05","2014-06","2014-07","2014-08","2014-09","2014-10","2014-11","2014-12",
"2015-01","2015-02","2015-03","2015-04","2015-05","2015-06","2015-07","2015-08","2015-09","2015-10","2015-11","2015-12",
"2016-01","2016-02","2016-03","2016-04","2016-05","2016-06","2016-07","2016-08","2016-09","2016-10","2016-11","2016-12",
"2017-01")
Actual_volume <- c(54447,57156,
52033,49547,58718,53109,56488,60095,54683,60863,56692,55283,55504,56633,
53267,52587,54680,55569,60013,56985,59709,61281,54188,59832,56489,55819,
59295,52692,56663,59698,61232,57694,63111,60473,58984,64050,54957,63238,
59460,54430,58901,61088,60496,62984,66895,62720,65591,67815,58289,72002,
61054,60329,69283,68002,63196,72267,71058,69539,71379,70925,68704,76956,
65863,70494,77348,70214,74770,77480,69721,83034,76761,77927,79768,81836,
75381)
df_data <- data.frame(Month_Names, Actual_volume)
trendDateRange1 <- c("2010-11-01", "2017-01-31")
trendDateRange2 <- c("2012-01-01", "2012-12-31")
trendDateRange3 <- c("2013-01-01", "2013-12-31")
numoftrends <- 3
trends <- data_frame(Start = c("2010-11", "2012-01", "2013-01"),
End = c("2017-01", "2012-12", "2013-12"))
combined_data <- df_data %>%
crossing(trends) %>%
mutate(Month_Names = as.character(Month_Names),
TrendName = paste(Start, End, sep = "-")) %>%
filter(Month_Names >= Start, …Run Code Online (Sandbox Code Playgroud) 我正在构建一个闪亮的应用程序,我想刷新主面板屏幕。这是示例代码。我有一个提交按钮来显示数据,我有一个刷新按钮来清除屏幕。我不太确定如何在 R 和闪亮中编写重新刷新按钮的代码,因为我对此很陌生。感谢您的关注
library(DT)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("amountTable", "Amount Tables", 1:10),
actionButton("submit1" ,"Submit", icon("refresh"),
class = "btn btn-primary"),
actionButton("refresh1" ,"Refresh", icon("refresh"),
class = "btn btn-primary")
),
mainPanel(
# UI output
uiOutput("dt")
)
)
)
server <- function(input, output, session) {
observeEvent(input$submit1, {
lapply(1:input$amountTable, function(amtTable) {
output[[paste0('T', amtTable)]] <- DT::renderDataTable({
iris[1:amtTable, ]
})
})
})
output$dt <- renderUI({
tagList(lapply(1:10, function(i) {
dataTableOutput(paste0('T', i))
}))
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud) 我在新的闪亮 R 中,但水平滚动有问题。这是我的代码。
output$sbirx.view <- DT::renderDataTable(
{
dataset.filter()
}, options = list(
searching = TRUE,
autoWidth=TRUE,
paging=FALSE,
scrollX=TRUE,
scrollY="500px",
scrollCollapse = TRUE,
fixedHeader=TRUE,
fixedColumns=list(leftColumns = 2, rightColumns = 0,
heightMatch = 'none')
),
rownames=FALSE,
class = 'cell-border stripe',
extensions = c('FixedColumns',"FixedHeader")
Run Code Online (Sandbox Code Playgroud)
)
数据有 79 列,我可以选择要显示的列数。前 2 个 leftcolumns(DISEASE 和 PRODUCT)应该是固定的,如果你只显示 3 列,表格看起来像这样。但是,如果我选择适合屏幕的几列,则没有问题。
疾病产品 疾病产品 2010-11 疾病1 产品1 疾病1 产品1 25,000 疾病1 产品2 疾病1 产品2 15,000 疾病1 产品3 疾病1 产品3 5,000
有没有办法使用任何选项来解决这个问题?
感谢您的时间和帮助。