r

Dynamic number of actionButtons tied to unique observeEvent

廉价感情. 提交于 2021-02-19 01:17:29
问题 I'd like to generate a dynamic number of actionButtons, and then have each generated button print its number to the console. This is my best attempt so far, but I still can't get the observeEvent for each of the first 10 buttons to recognize the button clicks. How do I tie the buttons to an observeEvent? library(shiny) ui <- basicPage( fluidRow( actionButton(inputId = "add_button", label = "Add Button") ), uiOutput("more_buttons") ) server <- function(input, output){ rvs <- reactiveValues

Dynamic number of actionButtons tied to unique observeEvent

放肆的年华 提交于 2021-02-19 01:16:13
问题 I'd like to generate a dynamic number of actionButtons, and then have each generated button print its number to the console. This is my best attempt so far, but I still can't get the observeEvent for each of the first 10 buttons to recognize the button clicks. How do I tie the buttons to an observeEvent? library(shiny) ui <- basicPage( fluidRow( actionButton(inputId = "add_button", label = "Add Button") ), uiOutput("more_buttons") ) server <- function(input, output){ rvs <- reactiveValues

How do you change the timezone of Sys.time()

我怕爱的太早我们不能终老 提交于 2021-02-18 22:38:49
问题 I am in the PDT timezone and I want to change the variable "s" to the GMT timezone. Any idea how? s<-Sys.time() s as.POSIXct(s,"GMT") OUTPUT > s<-Sys.time() > s [1] "2015-06-17 17:56:17 PDT" > as.POSIXct(s,"GMT") [1] "2015-06-17 17:56:17 PDT" # <-- how do I get this in GMT?? 回答1: Depending on what you want to do exactly, there are a couple of options: s <- Sys.time() s #[1] "2015-06-18 11:21:22 EST" Transfer from local time to GMT, without adustment: as.POSIXct(format(s),tz="GMT") #[1] "2015

R returning partial matching of row names

独自空忆成欢 提交于 2021-02-18 22:37:29
问题 I've run into the following issue vec <- c("a11","b21","c31") df <- data.frame(a = c(0,0,0), b = c(1,1,1), row.names = vec) df["a",] returns df["a",] a b a11 0 1 However, "a" %in% vec and "a" %in% rownames(df) both return False R is allowing for partial matching of the string when using letter followed by numbers for row names. I have replicated this on R v3.2.2 and R v3.2.1. Even df[["a",1,exact=T]] returns 0 Is there anything I can set such that R does not allow this partial matching? 回答1:

How do you change the timezone of Sys.time()

≡放荡痞女 提交于 2021-02-18 22:37:28
问题 I am in the PDT timezone and I want to change the variable "s" to the GMT timezone. Any idea how? s<-Sys.time() s as.POSIXct(s,"GMT") OUTPUT > s<-Sys.time() > s [1] "2015-06-17 17:56:17 PDT" > as.POSIXct(s,"GMT") [1] "2015-06-17 17:56:17 PDT" # <-- how do I get this in GMT?? 回答1: Depending on what you want to do exactly, there are a couple of options: s <- Sys.time() s #[1] "2015-06-18 11:21:22 EST" Transfer from local time to GMT, without adustment: as.POSIXct(format(s),tz="GMT") #[1] "2015

Data Prediction using Decision Tree of rpart

妖精的绣舞 提交于 2021-02-18 22:28:47
问题 I am using R to classify a data-frame called 'd' containing data structured like below: The data has 576666 rows and the column "classLabel" has a factor of 3 levels: ONE, TWO, THREE. I am making a decision tree using rpart: fitTree = rpart(d$classLabel ~ d$tripduration + d$from_station_id + d$gender + d$birthday) And I want to predict the values for the "classLabel" for newdata : newdata = data.frame( tripduration=c(345,244,543,311), from_station_id=c(60,28,100,56), gender=c("Male","Female",

Repel text from edges in network

柔情痞子 提交于 2021-02-18 22:23:06
问题 When drawing a network, it would be nice if the labels of the nodes could also avoid network edges. E.g. in the example below, it would be possible to move all the labels outside the network. I've tried several packages, but so far have not found even a hacky way to do that. Is there a way? Example below: library(ggraph) library(tidygraph) reprex <- tibble(to = sample(1:10, 100,replace=T), from = sample(1:10, 100,replace=T) ) %>% as_tbl_graph() V(reprex)$label1 <- rep("label",10) reprex_plot

plotly - where can I find the default color palette used in plotly package [duplicate]

南楼画角 提交于 2021-02-18 21:13:56
问题 This question already has answers here : How to get Plotly.js default colors list? (5 answers) Closed 4 years ago . I am primarily using the plotly package with r to plot my results. I would like to define the colors I use in my presentation document (tables, headings etc.) based on the default colors used in plotly. e.g. the colors used to fill the bars in a bar chart or the parts of a pie chart. Is there a way to find out the rgb or hex values? see the example here: https://plot.ly/r/pie

Plotting a regression line through the origin

这一生的挚爱 提交于 2021-02-18 21:13:04
问题 I am plotting some data series along with regression lines using this code: ggplot(dt1.melt, aes(x=lower, y=value, group=variable, colour=variable)) + geom_point(shape=1) + geom_smooth(method=lm, se=FALSE) However, I need to constrain the regression line to be through the origin for all series - in the same way as abline(lm(Q75~-1+lower,data=dt1)) would achieve on a standard R plot. Can anyone explain how to do this in ggplot ? 回答1: You need to specify this in the formula argument to geom

Plotting static base map underneath a sf object

≯℡__Kan透↙ 提交于 2021-02-18 21:01:48
问题 I'm trying to plot a static base map underneath my sf object (for print). When using ggmap I first get a lot of errors, then I can't seem to figure out how to chain the base map to my ggplot2 object with a geom_sf . library(sf) # devtools::install_github("tidyverse/ggplot2") library(ggplot2) library(ggmap) nc <- st_read(system.file("shape/nc.shp", package="sf")) nc_map <- get_map(location = "North Carolina, NC", zoom = 7) ggmap(nc_map) nc_centers <- st_centroid(nc) nc_centers %>% ggplot() +