我有这三个字符串:
letters <- "abc"
numbers <- "123"
mix <- "b1dd"
Run Code Online (Sandbox Code Playgroud)
如何检查这些字符串中的哪一个仅包含字母或仅包含数字(在R中)?
letters 只应在LETTERS ONLY检查中为TRUE
numbers 只应在NUMBERS ONLY检查中为TRUE
mix 在任何情况下都应该是假的
我现在尝试了几种方法,但它们都没有真正起作用:(
例如,如果我使用
grepl("[A-Za-z]", letters)
Run Code Online (Sandbox Code Playgroud)
它适用于letters,但它也适用于mix我不想要的.
提前致谢.
是否可以在加载绘图/反应元素时禁用闪亮的按钮?我知道shinyjs可以禁用和启用输入元素,但我不知道如何设置与加载图/反应元素的连接.该示例基于单文件闪亮应用程序页面.我刚刚添加了一个按钮和隔离的部分.不基于的解决方案shinyjs也赞赏:)
library(shiny)
server <- function(input, output) {
output$distPlot <- renderPlot({
input$button
isolate(
hist(rnorm(input$obs), col = 'darkgray', border = 'white')
)
})
}
ui <- fluidPage(
shinyjs::useShinyjs(),
sidebarLayout(
sidebarPanel(
sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100),
actionButton("button", "OK!")
),
mainPanel(plotOutput("distPlot"))
)
)
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
library(shiny)
library(ggplot2)
library(ggiraph)
df <- data.frame(achseX = LETTERS[1:24], achseY = 1:24, facetX = as.factor(rep(1:4, each = 6)))
server <- function(input, output) {
output$ggplot <- renderPlot({
ggplot(data = df) + geom_bar_interactive(aes(tooltip = achseY, x = achseX, y = achseY), stat = "identity") +
theme_minimal() + facet_grid(.~ facetX, scales = "free_x")
})
output$plot <- renderggiraph({
gg <- ggplot(data = df) + geom_bar_interactive(aes(tooltip = achseY, x = achseX, y = achseY), stat = "identity") +
theme_minimal() + facet_grid(.~ facetX, scales = "free_x") …Run Code Online (Sandbox Code Playgroud) 我的示例代码:
library(shiny)
server <- function(input, output) {
}
ui <- fluidPage(
br(),
selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE),
br(),
selectInput("select2", "Choose: ", c("Alt2.1", "Alt2.2"), selected = c("Alt2.1"), selectize = FALSE, multiple = TRUE)
)
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud)
我如何更改代码,使小部件的背景颜色为红色,为select1蓝色select2?
编辑:
我尝试了这个:
div(selectInput("select1", "Choose: ", c("Alt1.1", "Alt1.2"), selected = c("Alt1.1"), selectize = FALSE, multiple = TRUE), style = "background-color: red")
Run Code Online (Sandbox Code Playgroud)
但这不是我想要的!相反,我希望选项的背景为红色!
该图是使用以下代码生成的:
library(tidyverse)
library(plotly)
df <- data.frame(
DEP = c("ABC", "DEF", "GHI")
, VALUE = c(100, 110, 120)
, LINE = c(-0.1, 0.7, 0.9)
)
xAxis <- list(
title = ""
, tickangle = 0
, tickfont = list(size = 10)
)
yAxis <- list(
side = "left"
, showgrid = TRUE
, zeroline = TRUE
, title = ""
)
yAxis2 <- list(
side = "right"
, autotick = FALSE
, ticks = "outside"
, tick0 = 0
, dtick …Run Code Online (Sandbox Code Playgroud) 我的示例数据集:
df <- data.frame(
REGION = c("REGION A", "REGION A", "REGION B"),
CATEGORY = c("A", "B", "B"),
VALUE1 = c(2,3,4),
VALUE2 = c(1,2,3)
)
Run Code Online (Sandbox Code Playgroud)
结果:
REGION CATEGORY VALUE1 VALUE2
1 REGION A A 2 1
2 REGION A B 3 2
3 REGION B B 4 3
Run Code Online (Sandbox Code Playgroud)
现在我希望数据集中未考虑的 REGION 和 CATEGORY 的每个组合都填充为 0 的 VALUE1 和 VALUE2。结果df应该是:
REGION CATEGORY VALUE1 VALUE2
1 REGION A A 2 1
2 REGION A B 3 2
3 REGION B A 4 …Run Code Online (Sandbox Code Playgroud)