My dropdown should list files in a directory whose contents change frequently. I have tried:
menu = [(fname, fname) for fname in os.listdir(path)]
dropdown = Dropdown(label='files', menu=menu)
def on_click_handler():
logger.info('dropdown on click')
dropdown.menu = [(fname, fname) for fname in os.listdir(path)]
But when I click the dropdown button even the log statement is not created.
Both examples are for Bokeh v1.1.0
When using Python callback in Bokeh server app:
app.py (run from command line bokeh serve --show app.py)
from bokeh.models import Dropdown
from bokeh.plotting import curdoc
files1 = ['file1', 'file2']
files2 = ['file3', 'file4']
dropdown = Dropdown(label = 'files', menu = [(fname, fname) for fname in files1])
def on_click_handler():
dropdown.menu = [(fname, fname) for fname in files2]
dropdown.on_click(on_click_handler)
curdoc().add_root(dropdown)
When using JS callback in stand-alone Bokeh app:
app.py (run from command line python app.py)
from bokeh.models import CustomJS, ColumnDataSource, Select, Column, Dropdown
from bokeh.plotting import figure, curdoc, show
files1 = ['file1', 'file2']
files2 = ['file3', 'file4']
menu1 = [(fname, fname) for fname in files1]
menu2 = [(fname, fname) for fname in files2]
dropdown = Dropdown(label = 'files', menu = menu1)
on_click_handler = CustomJS(args = {'dropdown' : dropdown, 'menu2': menu2}, code = ''' dropdown.menu = menu2; ''')
dropdown.js_on_change('value', on_click_handler)
show(dropdown)
Related
I put a button in my shiny app, which download a table (called "tableau_final"), that i created in my code.
Howevever, when i print (on paper) the window of my app, i can see that my downloading button has sessions informations.
Is there a way to delete the session informations and just to see the download button like on the shiny app?
download button with session informations after printing the app window
My code is pretty basic :
output$Download_Tableau.xlsx <- downloadHandler(
filename = function() {
paste(input$type, ".xlsx", sep = "")
},
content = function(file){
fname <- paste(file,"xlsx",sep=".")
wb <- loadWorkbook(fname, create = TRUE)
createSheet(wb, name = "Detail")
writeWorksheet(wb, tableau_final, sheet = "Detail")
saveWorkbook(wb)
file.rename(fname,file)
}
)
I am working on creating a widget in R that can open a file and show the characteristics of that file within the same widget. I want this information to be updated automatically when loading the file. This means that I have the following function for the button that can open the file:
getfile <- function() {
name <- tclvalue(tkgetOpenFile(
filetypes = "{{raster files} {.tiff .tif .img .grd}} {{All files} *}"))
if (name == "") return;
Sys.sleep(10)
assign("Filename", name, envir = .GlobalEnv)
tclvalue(Filename) <- name
}
the function for the button that opens this file is:
button.widget <- tkbutton(tt, text = "Select File", command = getfile)
tkgrid(button.widget, pady=10, padx=10, columnspan=3)
The label is given by:
Filename <- tclVar("")
label.widget <- tklabel(tt, text=tclvalue(Filename))
tkgrid(label.widget, row=2, column=0)
However, when I create the widget everything works, Filename is changed and a file can be opened. But the text in the label is not changed. How can i fix this? Is there an event that can be run when I close the OpenFile dialog window?
Try:
tklabel (tt, textvariable=Filename)
There is this example where he configures the label as text first then reconfigures it with a textvariable. But you should be able to configure it as a textvariable initially. Caveat: I don't know R.
The alternative option is to put:
tkconfigure(label.widget,text=tclvalue(Filename))
At the end of the getfile() function.
I am trying to use the TableTools extension for DataTables to get a toolbar with copy, save, print and other options above a table in my Shiny App.
This is my server.R:
output$table <- DT::renderDataTable({
DT::datatable(datasetInput(),extensions = 'TableTools',options = list(
"sDom" = 'T<"clear">lfrtip',
"oTableTools" = list(
"sSwfPath" = "//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/swf/copy_csv_xls.swf",
"aButtons" = list(
"copy",
"print",
list("sExtends" = "collection",
"sButtonText" = "Save",
"aButtons" = c("csv","xls")
))
)
))
})
This is the output:
As you can see, there is no copy button. Also, when I click on the Save button, a tiny bar appears below it and the screen goes gray but nothing happens next.
This only happens when I try to run the app using Run in Window (R Studio). If I run it as External in Chrome, then there are no issues. Any help would be much appreciated. Thanks!
Where can I get a version of the shinyBS package that includes the bsModal() function. The version I have loaded on my machine does not have this function. I really need it. I am also having trouble locating documentation that includes bsModal(). Does this exist yet? I am assuming this is a relatively new functionality.
You will need shinyBS version 0.25 to get bsModal() or some other new features working. To do so you need to:
install_github("shinyBS", "ebailey78")
You will find the documentation related to bsModal() in the last tab of the shinyBS demo
Even so you will get the bootstrap 2.3.2 modal and not the latest v3.3.1. If you need the latest version, you can source:
# Adding a bootstrap 3 modal dialog
bsModalBoot3 <- function (id, title, trigger, ..., href)
{
mo <- tags$div(class = "modal sbs-modal fade", id = id, 'data-trigger' = trigger, tabindex="-1", role="dialog", 'aria-labelledby'="myModalLabel", 'aria-hidden'="true",
tags$div(class = "modal-dialog", tags$div(class = "modal-content", tags$div(class = "modal-header",
tags$button(type = "button", class = "close", 'data-dismiss' = "modal",
HTML("×")), tags$h3(class = "modal-title", id="myModalLabel", title)), body <- tags$div(class = "modal-body"),
tags$div(class = "modal-footer", tags$a(href = "#", class = "btn",
'data-dismiss' = "modal", "Close")))))
if (!missing(href)) {
mo <- addAttribs(mo, 'data-remote' = href)
}
else {
mo$children[[1]]$children[[1]]$children[[2]] <- tagAppendChildren(mo$children[[1]]$children[[1]]$children[[2]],
list = list(...))
}
return(mo)
}
You can look up the changes on my fork:
install_github("shinyBS", "Bolaka") - installs shinyBS vs 0.26
and call bsModalBoot3() to use the bootstrap 3.3.1 modal :)
I want to add a tooltip which pops up (at the position of the curser) by mouse hovering over the specific entry in a menubar.
I am using Windows, gwidgets with RGtk2 and R version 3.0.3
My code looks like this:
PG_top <- gwindow(...)
action_list = list (
open = gaction(label = "Open...", tooltip = "Open a File", icon = "open", handler = openDialogHandler, parent = PG_top)
)
menu_bar_list <- list(File = list (
Open = action_list$open
)
)
menu_bar <- gmenu(menu_bar_list, cont=PG_top)
I get no error messages nor any tooltip. Is this a toolkit Problem? I found a Handler called "addHandlerMouseMotion" but I don't know if this works for my kind of problem and what to do inside this Handler. If I try
tooltip<-(action_list[["open"]],"Open File")
or
tooltip<-(action_list$open,"Open File")
I get the errormessage: Error in (...): unexpected ","
Hope you can help me!